How to get this equation to plot
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Torsten
2023 年 9 月 25 日
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.
採用された回答
Voss
2023 年 9 月 25 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!