Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help with Code

Subject: Help with Code

From: Saptarshi Bhattacharjee

Date: 2 Jan, 2012 06:01:09

Message: 1 of 2

I have a problem where I am given a function f(x) where I need to plot the curve between f(x) and x. The problem I am facing is with dealing with the multiple outputs of f(x) for each x. Range of x is [0,4]. Can anyone help me with this??

Subject: Help with Code

From: Roger Stafford

Date: 2 Jan, 2012 07:12:07

Message: 2 of 2

"Saptarshi Bhattacharjee" wrote in message <jdrh75$md9$1@newscl01ah.mathworks.com>...
> I have a problem where I am given a function f(x) where I need to plot the curve between f(x) and x. The problem I am facing is with dealing with the multiple outputs of f(x) for each x. Range of x is [0,4]. Can anyone help me with this??
- - - - - - - - - -
  Could you please be more explicit about the statement "I am given a function"? In what form is the function given to you that would enable it to be multi-valued?

  As an example of what you might be facing, suppose you are given the implicit equation:

 (x-2)^2 + y^2 = 4

As we all know, this is the equation of a circle with center at (2,0) and radius 2, but if we try to express y as a function of x, we find that there are actually two functions:

 y = sqrt(x*(4-x))

and

 y = -sqrt(x*(4-x))

  You can either use both functions in creating a plot in two separate pieces, the upper half circle and the lower one, or else you can seek some parameter that will generate the entire curve. This latter parametric approach would look like this:

 a = linspace(0,2*pi); % Arc angles to points around the circle
 x = 2+2*cos(a); % x coordinates of those points
 y = 2*sin(a); % y coordinates of those points
 plot(x,y) % Plot y against x

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us