How can i plot the response of function as a vector ?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mallouli Marwa
el 7 de Mayo de 2016
Editada: Azzi Abdelmalek
el 7 de Mayo de 2016
Hi,
To resolve a secon order differential equation i do this function , but i have a problem when i want to plot xdot.
function xdot = equacte(t,x)
% Function file for mass with spring.
% Position is first variable, velocity is second variable,load is the third variable
freq=100; %frequency (Hz)
w=2*pi*freq;
m=0.0112;
k=262.8257 ;
teta =-4.40e+03;
cp= 1.8492*10^-7;
for rload =0:20:50000
A = [0,1,0;-k/m,0,-teta/m;(-teta/rload),0,-1/(rload*cp)];
B = [0;1/m;0];
f =sin(w*t);
xdot = A*x+B*f;
end
end
In the principle program :
[t,x]=ode45(@equacte,[0:0.0004:1],[0,0,0]);
xdot=equacte(t,x);
plot(t,xdot(:,1),'O',t,xdot(:,2),'r',t,xdot(:,3),'b');
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 7 de Mayo de 2016
Editada: Azzi Abdelmalek
el 7 de Mayo de 2016
What this line is doing? xdot=equacte(t,x) just write
[t,x]=ode45(@equacte,[0:0.0004:1],[0,0,0]);
plot(t,x(:,1),'O',t,x(:,2),'r',t,x(:,3),'b')
6 comentarios
Azzi Abdelmalek
el 7 de Mayo de 2016
Ok, but like you did it, the loop has no effect, only the last value will be taken in account.
Azzi Abdelmalek
el 7 de Mayo de 2016
Editada: Azzi Abdelmalek
el 7 de Mayo de 2016
Your function should look like
function xdot = equacte(t,x,rload)
% Function file for mass with spring.
% Position is first variable, velocity is second variable,load is the third variable
freq=100; %frequency (Hz)
w=2*pi*freq;
m=0.0112;
k=262.8257 ;
teta =-4.40e+03;
cp= 1.8492*10^-7;
A = [0,1,0;-k/m,0,-teta/m;(-teta/rload),0,-1/(rload*cp)]
B = [0;1/m;0];
f =sin(w*t);
xdot = A*x+B*f;
end
Then call it in the loop
for rload=2000:20:2040
[t,x]=ode45(@(t,x) equacte(t,x,rload),[0 1],[0,0,0]);
figure;
plot(t(2:end-1),diff(x))
end
Más respuestas (0)
Ver también
Categorías
Más información sobre Spectral Measurements 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!