represent differencital equation with ode45

2 次查看(过去 30 天)
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 个评论
Jan
Jan 2018-5-21
编辑:Jan 2018-5-21
BY the way, omit the last line, because it only replaces xdot by itself.
Anderson Francisco Silva
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)

请先登录,再进行评论。

采纳的回答

jose luis guillan suarez
编辑:jose luis guillan suarez 2018-5-29
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 个评论
Jan
Jan 2018-5-31
You are welcome. You can mark the question as solved by accepting an answer.
KARTHIK
KARTHIK 2023-11-15
编辑:KARTHIK 2023-11-15
Please guide for this problem by ode45
I need to plot amplitude vs velocity

请先登录,再进行评论。

更多回答(3 个)

Jan
Jan 2018-5-20
编辑:Jan 2018-5-29
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
and that's how i obtain the code from the equation:
  1 个评论
Jan
Jan 2018-5-21
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.

请先登录,再进行评论。


jose luis guillan suarez
编辑:jose luis guillan suarez 2018-5-22
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 个评论
Jan
Jan 2018-5-27
@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
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by