Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9062533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:45:39+00:00 2026-06-16T15:45:39+00:00

I am trying to plot mathematical functions and use the CoreGraphics framework. I am

  • 0

I am trying to plot mathematical functions and use the CoreGraphics framework. I am calculating a path by manually calculating the y-coordinate of a user defined mathematical function.

To draw the function I have included a simplified version of the code:

CGContextBeginPath(context);
CGContextMoveToPoint(context, coordinateSystemOriginX, coordinateSystemOriginY);

//Add all points
CGContextAddLineToPoint(context, newPoint.x,newPoint.y);

CGContextSetLineWidth(context, 2);
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextStrokePath(context); //Connect them

This is working fine but sadly the user might input a discontinous function like

 y = 10/x //undefined value for x=0

but the graph is drawn at x=0 and the points are connected.
See the image:

enter image description here

How can I evaluate undefined points so I am able to draw the graph correctly? I know there IS a solution as there are many plotting websites that draw the graph correctly.

A tip or any type of help would be greatly appreciated. Your are also free to include some magic piece of code 😉 Thanks!

 NSArray*undefinedPoints = [self someMagicFunction:(id)mathematicalExpression];
 //returns 0 for mathematicalExpression = 10/x and 1 for 10/(x-1)

BTW I am using the ANExpressionParser class to parse the user input. (http://mac.softpedia.com/progDownload/ANExpressionParser-Download-86833.html)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:45:40+00:00Added an answer on June 16, 2026 at 3:45 pm

    I assume you are advancing your x value at a fixed delta, possibly dependent on the resolution and zoom level.

    If you are lucky enough to actually divide by zero you’ll produce +Inf or -Inf and can check for that, and skip over that value when building your curve (splitting your curve into multiple parts), which solves your problem in that case.

    More generally and more often, you won’t actually divide by zero but instead will divide by a very small number, producing a result which is a very large number. You should be able to compare that value with the bounds of your viewport. If this value is outside the bounds of your viewport, you can decide to end that curve, and once a new value appears (for a new value of x) that is once again within your viewport you can begin a new curve, thus solving your problem in that case as well.

    If you are advancing your x value per-pixel then the above should be a solution.

    If you are advancing your x value more coarsely than per-pixel, then you will also have to deal with clipping the line segment, and with avoiding false positives with respect to detecting discontinuity.


    Also check to see if your particular library can produce for you a list of analytically determined discontinuities. With such a list ahead of time, you can split your curve into sections separated by those discontinuities.


    See also Division by Zero in Computer Arithmetic, Asymptotes, and Discontinuity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying plot data sets consisting of 3 coordinates: X-coordinate, x-coordinate and the
I'm trying to plot values as a function of the date (only hh:mm:ss, without
I am trying to plot some data using pylab scatter function. I'm using pylab.scatter(X,
I am trying to plot on the same figure the evolution of a function
I am trying to plot a function and its derivative using fplot . fplot('3*x*sin(x)
Trying to plot a signal function of 0 and 1, much like the solution
I'm trying to plot a function that contains a definite integral. My code uses
I'm trying to plot the derivative of a mollifier function in Mathematica. It differentiates
I'm trying to plot the following piecewise function in MATLAB: x=linspace(0,1,100); e=1; n=9; N(e,:)
I'm trying to plot some cities on Google's Geochart. This function works perfectly fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.