creating graphs from loops

i have two equations that require a loop to solve them. i need to create a graph from the loop with both equations on the same axis. however every time i attempt to do this each value in the loop is overwritten and so the graph on has one point. how do i save each point in the loop. the graph needs to be (y1 y1, m)
for m = (60:70)
y1 = (14*35)/(m*9.8)
y2 = (1 - exp((-14*7)/m
end

回答(2 个)

Hi Georgia,
You actually dont need a loop at all. You can get the answer easily using piecewise multiplication and division instead:
m=60:70;
y1=(14*35)./(m.*9.8);
y2=1-exp((-14*7)./m);
figure(), plot(m,y1,m,y2), legend('y1','y2')
I made the same assumptions about parentheses as the cyclist and that you want to plot y1 and y2 against m.
Here is one way that I typically solve that:
mrange = 60:70;
mcount = numel(mrange);
y1 = zeros(mcount,1);
y2 = zeros(mcount,1);
for mi = 1:mcount
y1(mi) = (14*35)/(mrange(mi)*9.8);
y2(mi) = (1 - exp((-14*7)/mrange(mi)));
end
figure
plot(mrange,y1,mrange,y2)
Note that your line of code for y2 had syntax errors with mismatched parentheses, which I corrected without much thought to what you intended to calculate there.

类别

帮助中心File Exchange 中查找有关 Graph and Network Algorithms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by