Clear Filters
Clear Filters

represent differencital equation with ode45

2 views (last 30 days)
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 Comments
Jan
Jan on 21 May 2018
Edited: Jan on 21 May 2018
BY the way, omit the last line, because it only replaces xdot by itself.
Anderson Francisco Silva
Anderson Francisco Silva on 29 Aug 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)

Sign in to comment.

Accepted Answer

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

Sign in to comment.

More Answers (3)

Jan
Jan on 20 May 2018
Edited: Jan on 29 May 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 on 21 May 2018
and that's how i obtain the code from the equation:
  1 Comment
Jan
Jan on 21 May 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.

Sign in to comment.


jose luis guillan suarez
jose luis guillan suarez on 22 May 2018
Edited: jose luis guillan suarez on 22 May 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 Comments
Jan
Jan on 27 May 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 on 27 May 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.

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!