How can I graph exponential functions?

1 view (last 30 days)
MC
MC on 13 Sep 2019
Answered: Star Strider on 13 Sep 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

Answers (1)

Star Strider
Star Strider on 13 Sep 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.

Categories

Find more on Programming 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!