필터 지우기
필터 지우기

represent differencital equation with ode45

조회 수: 2 (최근 30일)
jose luis guillan suarez
jose luis guillan suarez 2018년 5월 20일
편집: KARTHIK 2023년 11월 15일
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
Anderson Francisco Silva 2020년 8월 29일
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일
편집: 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
jose luis guillan suarez 2018년 5월 21일
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일
편집: 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
jose luis guillan suarez 2018년 5월 27일
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