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 日

0 投票

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 月 29 日
編集済み: Jan 2018 年 5 月 29 日
Running your code fails with an undefined function square(). I asked 9 days ago already... Assuming that it is the elementwise square of the input creates a completely different output:
So, Jose, please post running code. And even if someone like me suggests some code, it is your interest to debug it. It is strange, that after xdot = tresorden(t,x.').' the size of xdot is 185x187. It should be 185x3. So you have to provide the time t as row vector also:
xdot = tresorden(t.', x.').';
Then you can see, that xdot(:, 3) is the derivative of x(:, 3):
plot(t, gradient(x(:, 3), t), 'o')
hold on
plot(t, xdot(:, 3), '+')
Of course it is. Sorry for the forgotten transposition of the time vector. Using the debugger is strongly recommended in case of unexpected results.
jose luis guillan suarez
jose luis guillan suarez 2018 年 5 月 29 日
in my system runs perfectly, perhaps is the version of matlab. It's a square wave.
Jan
Jan 2018 年 5 月 29 日
Ah, thanks. You have the Signal Processing Toolbox installed in opposite to me.
After installing it, I get the expected results: xdot(:, 3) is the same as gradient(x(:, 3), t). I've fixed the code in my answer. Is your problem solved now?
jose luis guillan suarez
jose luis guillan suarez 2018 年 5 月 30 日
now is fixed , thank you very much.
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 日

0 投票

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 日

0 投票

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 日

0 投票

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 件のコメント

John D'Errico
John D'Errico 2018 年 5 月 22 日
Sigh. Stop adding answers every time you want to make a comment.
Jan
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
jose luis guillan suarez 2018 年 5 月 23 日
i can't understand how to solve it with initial values. I just want to represent the output of this system, represented with a differential equation. thanks.
jose luis guillan suarez
jose luis guillan suarez 2018 年 5 月 24 日
i think that is the x''' the variable that is not plotted.
jose luis guillan suarez
jose luis guillan suarez 2018 年 5 月 24 日
yes, i compared with the graphics from simulink and the variable not plotted is xdot(3)
Jan
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
jose luis guillan suarez 2018 年 5 月 26 日
編集済み: jose luis guillan suarez 2018 年 5 月 26 日
yes is the 3rd derivative what i need, but i checked numerically and the
xdot = tresorden(t,x.').';
plot(t, xdot(:, 3));
it's not the 3rd derivative.
Jan
Jan 2018 年 5 月 26 日
編集済み: Jan 2018 年 5 月 27 日
@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
jose luis guillan suarez 2018 年 5 月 26 日
the original equation is this. ¿is it possible to obtain the 3rd derivative?
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGeneral Applications についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by