Plotting Mathematica f[r_][x_]: Solving Derivatives & Plotting Lines

In summary, the conversation discusses creating a function f[r][x] and solving it for various values of r to obtain the function cps[r]. The speaker then wants to use this information to plot the values of the derivative of f with each value of r, with solid lines for values less than 0 and dashed lines for values greater than 0. The solution involves defining a new function g[r] using the previously obtained cps[r] values and using Plot and Manipulate to create the desired plot. The speaker also asks if there is a way to automatically define g[r] as a function without doing it manually.
  • #1
Dustinsfl
2,281
5
Code:
f[r_][x_] := 1 + r*x + x^2;
A = Table[
   cps[r_] = x /. Quiet[Solve[f[r][x] == 0, x], Solve::ratnz], {r, -5,
     5, 0.01}];

I want to then tell mathematica to check the derivative of f with each value from the table, plot the values, but make the lines where there derivative in less than 0 solid and dashed for greater than 0.

Any ideas on how to finish this?
 
Physics news on Phys.org
  • #2
dwsmith said:
Code:
f[r_][x_] := 1 + r*x + x^2;
   cps[r_] = x /. Quiet[Solve[f[r][x] == 0, x], Solve::ratnz]

I want to then tell mathematica to check the derivative of f with each value from the table, plot the values, but make the lines where there derivative in less than 0 solid and dashed for greater than 0.

Any ideas on how to finish this?

So I got rid of the table.
Code:
f[r_][x_] := 1 + r*x + x^2;
cps[r_] = x /. Quiet[Solve[f[r][x] == 0, x], Solve::ratnz];
g[r_] = x /. Quiet[Solve[f[r][x] == 0, x], Solve::ratnz]
Plot[g[r], {r, -5, 5}, PlotStyle -> {Red, Thick}]
{1/2 (-r - Sqrt[-4 + r^2]), 1/2 (-r + Sqrt[-4 + r^2])}
Manipulate[Plot[f[r][x], {x, -4, 4}], {r, -10, 10}]

y[r_] = 1/2 (-r - Sqrt[-4 + r^2]);
t[r_] = 1/2 (-r + Sqrt[-4 + r^2]);
Plot[{y[r], t[r]}, {r, -5, 5}, 
 PlotStyle -> {{Dashing[{Medium}], Red}, {Thick, Red}}]

I can create what I want be defining the g[r] output but is there a way to have the g[r] output automatically defined as functions without doing it by hand?
 

What is the purpose of plotting Mathematica f[r_][x_]: Solving Derivatives & Plotting Lines?

The purpose of this function is to allow users to plot the graph of a mathematical function, as well as its derivative, in order to visualize the relationship between the two. This can aid in understanding the behavior of the function and its rate of change.

How do I input a mathematical function into the f[r_][x_] function?

To input a mathematical function, you will need to define the function using the appropriate syntax. For example, if you wanted to plot the function f(x) = x^2, you would type f[x_]:= x^2. This tells Mathematica to define the function f with the variable x and its corresponding expression.

Can I plot multiple functions using this function?

Yes, you can plot multiple functions by defining each function separately and then using the Plot function to plot them all on the same graph. For example, if you wanted to plot f(x) = x^2 and g(x) = x^3, you would first define both functions and then use the command Plot[{f[x], g[x]}, {x, -5, 5}] to plot them.

How do I plot the derivative of a function using this function?

In order to plot the derivative of a function, you will first need to define the function using the f[r_][x_] syntax and then use the command Plot[f'[x], {x, -5, 5}]. This will plot the derivative of the function f over the range of values specified.

Can I customize the appearance of the graph using this function?

Yes, there are several options available for customizing the appearance of the graph, such as changing the color, style, and thickness of the lines. You can also add a title, labels for the axes, and a legend to the graph. Additionally, you can change the range of values for the x and y axes to zoom in or out on specific parts of the graph.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
227
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
Back
Top