Borrar filtros
Borrar filtros

represent differencital equation with ode45

2 visualizaciones (últimos 30 días)
jose luis guillan suarez
jose luis guillan suarez el 20 de Mayo de 2018
Editada: KARTHIK el 15 de Nov. de 2023
i got this differential equation:
function xdot=tresorden(t,x)
xdot=zeros(3,1);
Vp=5;
Vi=Vp*square(2*pi*t)+5;
xdot(1)=x(2);
xdot(2)=x(3);
xdot(3)=6*Vi-6*x(1)-11*x(2)-6*x(3);
xdot=[xdot(1);xdot(2);xdot(3)];
how can i represent x(1)?
  2 comentarios
Jan
Jan el 21 de Mayo de 2018
Editada: Jan el 21 de Mayo de 2018
BY the way, omit the last line, because it only replaces xdot by itself.
Anderson Francisco Silva
Anderson Francisco Silva el 29 de Ag. de 2020
And if he wanted to use the last vector, to be entered in another function he could do it like this? :
xdot(3)=6*Vi-6*x(1)-11*x(2)-6*x(3);
x_dot=[xdot(1);xdot(2);xdot(3)]; (I chance the name of vector, for no replaces xdot)

Iniciar sesión para comentar.

Respuesta aceptada

jose luis guillan suarez
jose luis guillan suarez el 29 de Mayo de 2018
Editada: jose luis guillan suarez el 29 de Mayo de 2018
i'm going to collect what i have so far. this is the function:
function xdot=tresorden(t,x)
xdot=zeros(3,1);
Vp=5;
Vi=Vp*square(2*pi*t)+5
xdot = [x(2, :);
x(3, :);
6 * Vi - 6 * x(1, :) - 11 * x(2, :) - 6 * x(3, :)];
those are the commands:
%to evaluate the function
[t,x]=ode45('tresorden',[0,10],[0,0,0])
%to plot the x''
plot(t, x(:, 2));
hold on
%to plot the x'''
xdot = tresorden(t,x.').';
plot(t, xdot(:, 3));
%this should plot the x''' but it doesn't, as you can check in the graphics
in the graphics you can see that in the matlab plot the blue graphic (x''') is not the derivative of the red graphic (x'')
in the simulink output you can see that the blue graphic (x''') IS the derivative of the red graphic (x'')
i can't uderstand what is happening, perhaps there is a mistake on the definition of the function in matlab.
  6 comentarios
Jan
Jan el 31 de Mayo de 2018
You are welcome. You can mark the question as solved by accepting an answer.
KARTHIK
KARTHIK el 15 de Nov. de 2023
Editada: KARTHIK el 15 de Nov. de 2023
Please guide for this problem by ode45
I need to plot amplitude vs velocity

Iniciar sesión para comentar.

Más respuestas (3)

Jan
Jan el 20 de Mayo de 2018
Editada: Jan el 29 de Mayo de 2018
This integrates the function from the start point x=[1,2,3] over the time 0 to 7:
[EDITED - bug concerning t.' fixed]
function main
[t, x] = ode45(@tresorden, [0, 7], [1,2,3]);
plot(t, x(:, 1));
xdot = tresorden(t.', x.').';
end
function xdot = tresorden(t, x)
Vp = 5;
Vi = Vp * (2*pi*t)^2 + 5; % Or what is square() ?
xdot = [x(2, :); ...
x(3, :); ...
6 * Vi - 6 * x(1, :) - 11 * x(2, :) - 6 * x(3, :)];
end
Note: Due to square you are integrating a non-smooth system. This causes numerical instabilities. See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047.

jose luis guillan suarez
jose luis guillan suarez el 21 de Mayo de 2018
and that's how i obtain the code from the equation:
  1 comentario
Jan
Jan el 21 de Mayo de 2018
Sure? I'd expect:
xdot(1) = x(2);
xdot(2) = x(3);
xdot(3) = Vi - 6*x(3) - 11*x(2) - 6*x(1);
if you convert the 3rd order equation to a system of 1st order.
But even then: ODE45 is used to solve initial value problems numerically. If you want the values of x(1), you need to run the integration from an initial value.
Please do not post parts of the question in the section for answer. And explain, what "represent differencital equation with ode45" means exactly.

Iniciar sesión para comentar.


jose luis guillan suarez
jose luis guillan suarez el 22 de Mayo de 2018
Editada: jose luis guillan suarez el 22 de Mayo de 2018
excuse if i didn't explained myself well: what i want to represent the variable selected in the picture. (if possible) and plot it with:
[t,x]=ode45('tresorden',[0,10],[0,0,0]
plot(t,x)
  11 comentarios
Jan
Jan el 27 de Mayo de 2018
@jose: You have posted and removed another equation formerly. The solution of how to get the 3rd derivative has been given repeatedly and it even occurs in the original question.
Currently my best assumption is that your "numerical checking" contains a mistake.
i checked numerically and the [...] it's not the 3rd derivative.
My best assumption is that your "numerical check" contains a mistake.
After 6 days it could not be clarified, what the actual question is or why the obvious and already posted solution does not satisfy you. Therefore I will leave this thread now.
jose luis guillan suarez
jose luis guillan suarez el 27 de Mayo de 2018
i checked it numerically, and i compared with the result of the simulation of the system in simulink. The outputs of x'',x' and x match with the ones from matlab but x''' doesn't match. I checked it numerically and the righ output is the one from simulink. I attached the scheme of simulink.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by