Group Abstract Group Abstract

Message Boards Message Boards

0
|
16.1K Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How Do I Plot a Function With Two Variables?

Posted 10 years ago

How do I get mathematica to plot (using the piece wise command) the function :

R(x)={{a*x + 8, x <= -3}, {x^2 + 2*a^2, x > -3}}

I typed the function:

R[x_,a_] := Piecewise[{a*x + 8, x <= -3}, {x^2 + 2*a^2, x > -3}] 

and both the x and a variables turned green. How do I properly type the plot command to produce a graph?

POSTED BY: Tyler Dunlap
4 Replies
POSTED BY: Gianluca Gorni
Posted 10 years ago

'A' is a constant not a variable and I am trying to plot the function to find it's limits to solve for the value of 'a'

POSTED BY: Tyler Dunlap
Posted 10 years ago

Hi,

you forgot to write x_ instead x and the outer brackets { } in Piecewise. With Plot3D you obtain

R[x_, a_] := Piecewise[{{a x + 8, x <= -3}, {x^2 + 2 a^2, x > -3}}];
Plot3D[R[x, a], {x, -10, 10}, {a, -5, 5}]

which gives you a plot. If "a" is just a constant, which needs to be determined for a plot and not really a variable I would try the following

R[x_] := Piecewise[{{a x + 8, x <= -3}, {x^2 + 2 a^2, x > -3}}];
Plot[R[x] /. a -> 2, {x, -10, 10}]

/. a-> is similar to the With operator, which might have been used here as well, and sets the values locally.

POSTED BY: Till Luc Lange

Well, that depends on what you want. First of all, you should define R as a function of dummy variables (patterns, the little underscores after the letters), and you're missing a set of curly braces in your Piecewise:

R[x_, a_] := Piecewise[{{a x + 8, x <= -3}, {x^2 + 2 a^2, x > -3}}]

You could now do various types of plots; for instance, you can pick a value of a that you're interested in and do a Plot for that value. Or you can play around with Manipulate to find an interesting a. You could also use Plot3D to create a 3D plot of R versus both x and a. Starting from these functions, I'll let you explore the Documentation a bit - you can always come back if you need more specific help.

POSTED BY: Bianca Eifert
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard