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 commentaires

Walter Roberson
Walter Roberson le 8 Oct 2017
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 le 8 Oct 2017
Yeah, i corrected it. Sorry for this. It will be like;

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 8 Oct 2017

0 votes

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 commentaires

Berkcan Oz
Berkcan Oz le 8 Oct 2017
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.
[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 le 8 Oct 2017
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 le 10 Oct 2017
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 le 10 Oct 2017
It worked for me, thanks for help. I understood because of you, thanks a lot.

Connectez-vous pour commenter.

Plus de réponses (1)

Community Treasure Hunt

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

Start Hunting!

Translated by