How do I plot an equation that requires I divide over a range?
Show older comments
r = 0.01:0.02;
t = -0.3/r + 398.15
plot(r,t);
%how do I get this to work correctly?
%im trying to plot the equation t over the range of r on a graph
Answers (1)
Star Strider
on 4 Oct 2020
There are (at least) two problems:
First:
r = 0.01:0.02;
the default step for the colon,: operator is 1, so the range for ‘r’ is satisfied for the first increment, then stops, so ‘r’ returns a scalar as the first value only.
Second, you need to use element-wise division:
t = -0.3./r + 398.15;
↑ ← HERE
to get the vector you want.
With both of these issues fixed, see if:
r = 0.01:0.001:0.02;
t = -0.3./r + 398.15
plot(r,t)
does what you want.
Categories
Find more on Get Started with MATLAB 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!