Plotting two function in one figure
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ali A
am 1 Jun. 2015
Bearbeitet: Walter Roberson
am 1 Jun. 2015
calculate y(t) for the following equation:
y(t) = -2*t^3+5 (t>=0) and y(t) = 2*t^3+5 (t<0).
The values of y should be calculated in the range -9 <= t <= 9. Calculate
a value of y for every t in increments of 0.1 in the range specified. The
values of y should be collected in a single array. Generate a plot of y vs.
t using the plot command. The curve should be in solid green line with width
of 2. Make sure you have proper axis labels.
This is what I've come up too:
t = [ -9 : 0.1 : 9 ];
for ii = t >= 0
y = -2*t.^(3)+5;
end
for jj = t<0
y = 2*t.^(3)+5;
end
plot(y , 'g', 'linewidth',2)
I'm wondering shouldn't my x axis be the t values, I think I've got something missing here.
0 Kommentare
Akzeptierte Antwort
Ingrid
am 1 Jun. 2015
you are not storing your values in a vector y since therefor you would need to indicate y(ii). Also the for command will not be working, instead you need to use a logical indexing
t = [ -9 : 0.1 : 9 ];
y(t>=0) = -2*t(t>=0).^(3)+5;
y(t<0) = 2*t(t<0).^(3)+5;
plot(t,y , 'g', 'linewidth',2)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!