How can I graph exponential functions?

2 visualizzazioni (ultimi 30 giorni)
MC
MC il 13 Set 2019
Risposto: Star Strider il 13 Set 2019
f = @(t,y) 2*y+4-t;
t = 0:0.05:0.5;
y = -2:0.05:-1.5;
dirfield(f,t,y)
hold on
t = linspace(0,5,100);
y1 = (2*exp(-2*t)-7*exp(-2*t)+0.6)/(4*exp^(-2*t));
y2 = (2*exp(-2*t)-7*exp(-2*t)+0.2)/4*exp^(-2*t);
y3 = (2*exp(-2*t)-7*exp(-2*t)-0.2)/4*exp^(-2*t);
y4 = (2*exp(-2*t)-7*exp(-2*t)-0.6)/4*exp^(-2*t);
plot(t,y1,'b',t,y2,'b',t,y3,'b',t,y4,'b')
hold off
savefig('M1.fig')
Error Message=
Error in M1 (line 7)
y1 = (2*exp(-2*t)-7*exp(-2*t)+0.6)/(4*exp^(-2*t));
M1
Error using exp
Not enough input arguments, I want to graph the differential euqations with various IVP
Thanks

Risposte (1)

Star Strider
Star Strider il 13 Set 2019
First, do not use the exponentiation operator here:
y1 = (2*exp(-2*t)-7*exp(-2*t)+0.6)/(4*exp^(-2*t));
and use element-wise multiplication (.*) and division (./) operations:
y1 = (2*exp(-2*t)-7.*exp(-2*t)+0.6)./(4*exp(-2*t));
Do the same with all of them, and remember the parentheses in the denominator on the others.

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by