How to get this equation to plot

조회 수: 2 (최근 30일)
Jon
Jon 2023년 9월 25일
댓글: Torsten 2023년 9월 25일
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
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
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개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by