How to get this equation to plot
2 views (last 30 days)
Show older comments
I am trying to plot this equation and matlab thinks it is matrix multiplication when it is not. I have included my code. I also included a screen shot of what matlab is telling me.
%x1'=10e^-3t*-sin(200t)+2e^-3t*cos(200t)
%x2'=-10e^-3t*cos(200t)+2e^-3t*sin(200t)
tspan=[-10 10];
x1=10*exp(-3*t)*(-sin(200*t))+2*exp(-3*t)*cos(200*t);
x2=-10*exp(-3*t)*cos(200*t)+2*exp(-3*t)*sin(200*t);
figure
hold on
fplot(x1,tspan,'r');
fplot(x2,tspan,'b');
xlim([0 1]);
ylim([-10 10]);
xlabel('Time');
ylabel('Solutions')
title('{x1(t)}, {x2(t)}');
grid on
hold off
1 Comment
Torsten
on 25 Sep 2023
You are given the derivatives x1' and x2' of x1 and x2. You need to apply MATLAB's "int" to determine their antiderivatives first before plotting.
Accepted Answer
Voss
on 25 Sep 2023
Use .* for element-wise multiplication, and if you want to use fplot then x1 and x2 should be function handles (I've added "@(t)" at the beginning of their definitions to do so).
%x1'=10e^-3t*-sin(200t)+2e^-3t*cos(200t)
%x2'=-10e^-3t*cos(200t)+2e^-3t*sin(200t)
tspan=[-10 10];
x1=@(t)10*exp(-3*t).*(-sin(200*t))+2*exp(-3*t).*cos(200*t);
x2=@(t)-10*exp(-3*t).*cos(200*t)+2*exp(-3*t).*sin(200*t);
figure
hold on
fplot(x1,tspan,'r');
fplot(x2,tspan,'b');
xlim([0 1]);
ylim([-10 10]);
xlabel('Time');
ylabel('Solutions')
title('{x1(t)}, {x2(t)}');
grid on
hold off
0 Comments
More Answers (0)
See Also
Categories
Find more on Line Plots 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!