I have a homework, i did some part of it but i cannot do the second part. There is u(t) but I do not know how to use, is it Heaviside or other things ? Can you help me ?
It is question :
And it is my incomplete solution :
1-
2-

2 件のコメント

Walter Roberson
Walter Roberson 2017 年 10 月 8 日
That definition of u(t) is inconsistent. It requires that u(t) = 10 when t = 0.5 exactly, but it also requires that u(t) = 5 when t = 0.5 exactly.
Berkcan Oz
Berkcan Oz 2017 年 10 月 8 日
Yeah, i corrected it. Sorry for this. It will be like;

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

 採用された回答

Walter Roberson
Walter Roberson 2017 年 10 月 8 日

0 投票

You cannot do that in a single ode45 call. You need to break it up at t = 0.5.
The reason for this is that ode45() cannot be used to integrate when there are discontinuities in the function or in the derivatives, or for at least one further derivative more than is coded (it will be estimated numerically), and possibly not even for one more derivative beyond that. At the point of discontinuity you have to end the ode45 call. So you can calculate once for 0 to 0.5 with a function that knows u(t) is 10, and get out the t and y values from it. You then take the last of the y values and use it as your initial values for another call to ode4 over 0.5 to 1, with u(t) = 5.

5 件のコメント

Berkcan Oz
Berkcan Oz 2017 年 10 月 8 日
I did not think that way. How do I break ode45? By using end or what ? When I learn how to break ode45, i will do some correction on my code and I will share it again.
Walter Roberson
Walter Roberson 2017 年 10 月 8 日
[t, y] = ode45(@firstFunction, [0 1/2], InitialConditions)
[t2, y2] = ode45(@secondFunction, [1/2 1], y(end,:))
where firstFunction implements the system for u(t) = 10, and secondFunction implements the system for u(t) = 5
Then,
T = [t; t2(2:end)];
Y = [y; y2(2:end,:)];
plot(T, Y)
Berkcan Oz
Berkcan Oz 2017 年 10 月 8 日
Sorry, I did not understand very well. I am new at MATLAB. Can you explain it in simple way ?
I did this but it did not work :
Walter Roberson
Walter Roberson 2017 年 10 月 10 日
ts1 = [0 .5];
ts2 = [0.5 1];
i = [1 -1 0];
cdd = @(t,y, u) [y(2); y(3); (u + 2*y(2) - y(1))/3];
[t1, y1] = ode45(@(t,y) cdd(t, y, 10), ts1, i);
[t2, y2] = ode45(@(t,y) cdd(t, y, 5), ts2, y1(end,:));
T = [t1; t2(2:end)];
Y = [y1; y2(2:end,:)];
plot(T, Y)
Berkcan Oz
Berkcan Oz 2017 年 10 月 10 日
It worked for me, thanks for help. I understood because of you, thanks a lot.

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

その他の回答 (1 件)

Berkcan Oz
Berkcan Oz 2017 年 10 月 9 日

0 投票

Nobody help ?

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by