How to get this equation to plot
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jon
el 25 de Sept. de 2023
Comentada: Torsten
el 25 de Sept. de 2023
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 comentario
Torsten
el 25 de Sept. de 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.
Respuesta aceptada
Voss
el 25 de Sept. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!