How can I graph exponential functions?

1 次查看(过去 30 天)
MC
MC 2019-9-13
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

回答(1 个)

Star Strider
Star Strider 2019-9-13
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.

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by