Matlab Second Derivative Ploting Problem

In summary, to plot the derivative of a function in MatLab, make sure the arrays used for the theta and v values are the same size, and add a zero to the v array before using the polar command.
  • #1
Zaragoza_S
1
0
Question: How can I plot the derivative of a function?

Following code for problem 5.9 in MatLab by Gilat 4th Ed:

t=[0:1:20];
theta=pi*(1-exp(-0.2*t));
r=20+30*(1-exp(-0.1*t));
v=diff(theta)
table=[t' theta' r']
polar(theta,r)
polar(theta,v)

Error message:

? Error using ==> polar at 61
THETA and RHO must be the same size.

Error in ==> Prob5_16 at 12
polar(theta,v)



I have looked around for what may be the larger issue and it seems that when you use the "diff" function it shortens one dimension of the array (https://www.physicsforums.com/showthread.php?t=55524)

Any help please? The link provides "an answer" but i don't understand what he means.
 
Physics news on Phys.org
  • #2
Answer: To plot the derivative of a function, you need to make sure that the arrays used for the theta and v values have the same size. The diff function shortens one dimension of the array, so you will need to add in a zero value to make them equal. You can do this by adding the following line of code before the polar command:v = [0, v];This will add a zero at the start of the v array, making it the same length as the theta array. After doing this, the polar command should work correctly.
 

Related to Matlab Second Derivative Ploting Problem

What is the purpose of plotting the second derivative in Matlab?

The second derivative is a measure of the rate of change of the first derivative. Plotting the second derivative can help visualize the curvature and inflection points of a function, which are important in understanding its behavior.

How do I plot the second derivative of a function in Matlab?

To plot the second derivative of a function in Matlab, you can use the diff function twice. First, use diff to find the first derivative, and then use it again on the result to find the second derivative. Then, use the plot function to plot the second derivative values against the corresponding x-values.

Why is my second derivative plot not smooth?

The second derivative plot may not appear smooth if the function being plotted is not smooth itself. This can happen if there are discontinuities or sharp changes in the function. In this case, you may need to use a smaller step size in your plot function to get a more accurate representation of the second derivative.

How can I determine the maximum and minimum values of a function using the second derivative plot?

The maximum and minimum values of a function can be found by looking for the points where the second derivative changes from positive to negative (for a maximum) or from negative to positive (for a minimum). These points correspond to the inflection points of the function, where the curvature changes from concave up to concave down (for a maximum) or from concave down to concave up (for a minimum).

Can I use the second derivative to find the critical points of a function?

Yes, the critical points of a function can be found by looking for the points where the second derivative is equal to 0. These points correspond to the points of inflection where the curvature changes from positive to negative (for a local maximum) or from negative to positive (for a local minimum). However, it is important to note that not all points where the second derivative is 0 are critical points, so further analysis may be needed.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Differential Equations
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top