represent differencital equation with ode45
이전 댓글 표시
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
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)
채택된 답변
추가 답변 (3개)
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
2018년 5월 21일
0 개 추천
댓글 수: 1
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
2018년 5월 22일
편집: jose luis guillan suarez
2018년 5월 22일
0 개 추천
댓글 수: 11
John D'Errico
2018년 5월 22일
Sigh. Stop adding answers every time you want to make a comment.
Jan
2018년 5월 23일
@jose luis guillan suarez: And I still repeat, that the only way to get the trajectory to x(1) is the solution of the initial value problem.
jose luis guillan suarez
2018년 5월 23일
jose luis guillan suarez
2018년 5월 24일
jose luis guillan suarez
2018년 5월 24일
Jan
2018년 5월 25일
I cannot follow you. Which graphics did you compare with what? You did not post any code for plotting yet. ODE45 replies a matrix of [x, x', x''] (where the quote means the derivative here!). If you want the value of the 3rd derivative, you need:
function main
[t, x] = ode45(@tresorden, [0, 7], [1,2,3]);
xdot = tresorden(t,x.').';
plot(t, x(:, 1));
hold on;
plot(t, x(:, 2));
plot(t, x(:, 3));
plot(t, xdot(:, 3));
end
function xdot = tresorden(t, x)
Vp = 5;
Vi = Vp * (2*pi*t) .^ 2 + 5;
xdot = [x(2, :); ...
x(3, :); ...
6 * Vi - 6 * x(1, :) - 11 * x(2, :) - 6 * x(3, :)];
end
But this is still an initial value problem...
jose luis guillan suarez
2018년 5월 26일
편집: jose luis guillan suarez
2018년 5월 26일
@jose: Is this a serious question? xdot(:,3) is the 3rd component of the equation you have posted. You had posted an ODE of order 3, which was not equivalent to the converted system of order 1, but the original equation was deleted later. As I have written above, the 3rd component of the original ODE of order 3 would differ by a factor 6 for Vi.
xdot(3) = Vi - 6*x(1, :) - 11*x(2, :) - 6*x(3, :)
So please check your conversion of the ODE again.
Simply mentioning "it's not the 3rd derivative" is not useful in the forum. We cannot read your mind, your screen or the original equation. You have to provide the information.
jose luis guillan suarez
2018년 5월 26일
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
2018년 5월 27일
카테고리
도움말 센터 및 File Exchange에서 General Applications에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!








