Effacer les filtres
Effacer les filtres

represent differencital equation with ode45

2 vues (au cours des 30 derniers jours)
jose luis guillan suarez
jose luis guillan suarez le 20 Mai 2018
Modifié(e) : KARTHIK le 15 Nov 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 commentaires
Jan
Jan le 21 Mai 2018
Modifié(e) : Jan le 21 Mai 2018
BY the way, omit the last line, because it only replaces xdot by itself.
Anderson Francisco Silva
Anderson Francisco Silva le 29 Août 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)

Connectez-vous pour commenter.

Réponse acceptée

jose luis guillan suarez
jose luis guillan suarez le 29 Mai 2018
Modifié(e) : jose luis guillan suarez le 29 Mai 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 commentaires
Jan
Jan le 31 Mai 2018
You are welcome. You can mark the question as solved by accepting an answer.
KARTHIK
KARTHIK le 15 Nov 2023
Modifié(e) : KARTHIK le 15 Nov 2023
Please guide for this problem by ode45
I need to plot amplitude vs velocity

Connectez-vous pour commenter.

Plus de réponses (3)

Jan
Jan le 20 Mai 2018
Modifié(e) : Jan le 29 Mai 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 le 21 Mai 2018
and that's how i obtain the code from the equation:
  1 commentaire
Jan
Jan le 21 Mai 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.

Connectez-vous pour commenter.


jose luis guillan suarez
jose luis guillan suarez le 22 Mai 2018
Modifié(e) : jose luis guillan suarez le 22 Mai 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 commentaires
Jan
Jan le 27 Mai 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 le 27 Mai 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by