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.
[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 :
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 ?

카테고리

질문:

2017년 10월 8일

댓글:

2017년 10월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by