How to plot functions within a range?
Show older comments
My question is how to plot trigonometric functions within a specified range. This is the code fragment from the script
x = linspace(-2*pi, 2*pi);
y = tan(x);
dy = diff(y);
plot(x,y,x,dy);
When I run the code I receive de following error.
Error using plot
Vectors must be the same length.
Any sort of help and advice is more than welcome
Accepted Answer
More Answers (1)
Walter Roberson
on 7 Mar 2018
0 votes
You are applying diff() to a numeric array. That is defined by simple numeric differences.
If you were to use points closer and closer together then the mathematical limit as the distance approaches 0 would be the calculus differentiation. But only in the limit: numeric diff() approximates derivative half way between points.
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!