data not showing up
Mostrar comentarios más antiguos
IC=[0 0 0 0 0 0];
ti=0;
tf=20;
tspan=[ti,tf];
h = 1;
%Scenario 1
fMu1=@(t,y)Mu(t,y,ti,tf,1);
[t1,y1]=ode45(fMu1,tspan,IC);
figure()
hold on
subplot(3,1,1)
plot(t1,y1(:,1),t1,y1(:,3),t1,y1(:,5))
legend('x1', 'x2', 'x3')
xlabel('t')
ylabel('positions');
title('Scenario 1: Positions')
subplot(3,1,2)
plot(t1,y1(:,2),t1,y1(:,4),t1,y1(:,6))
legend('v1', 'v2', 'v3')
xlabel('t')
ylabel('velocities');
title('scenario 1: velocities')
%excitation
%subplot(3,1,3)
hold off
sc1res1 = myEuler3(fMu1,IC,ti,tf,h)
prob1res1 = array2table(sc1res1', 'VariableNames',{'t','x1','v1','x2','v2','x3','v3'})
sc1res2 = myHeun(fMu1,IC,ti,tf,h)
prob1res2 = array2table(sc1res2', 'VariableNames',{'t','x1','v1','x2','v2','x3','v3'})
sc1res3 = myRK4(fMu1,IC,ti,tf,h);
prob1res3 = array2table(sc1res3', 'VariableNames',{'t','x1','v1','x2','v2','x3','v3'})
When I run this function, the plots show up fine but in the myEuler3 and myHeun cases, all the columns except the first show up as all zeros. The myRK4 case also runs fine. I don't think it's a problem with the functions because they've run perfectly in other examples but i'll post them here anyway.
function [sol] = myEuler3(F, y0, ti, tf, h)
t = ti:h:tf;
y = zeros(length(y0),length(t));
y(:,1) = y0;
for i = 2:length(t)
y(:,i) = y(:,i-1) + h*F(t(i-1),y(:,i-1));
end
sol = [ t; y ];
end
function [sol] = myHeun(F, y0, ti, tf, h)
t = ti:h:tf;
y = zeros(length(y0),length(t));
y(:,1) = y0;
for i = 2:length(t)
yp = y(:,i-1) + h*F(t(i-1),y(:,i-1));
y(:,i) = y(:,i-1) + 0.5*h*(F(t(i-1),y(:,i-1))+F(t(i),yp));
end
sol = [ t; y ];
end
5 comentarios
Susan Santiago
el 13 de Mayo de 2018
KALYAN ACHARJYA
el 13 de Mayo de 2018
Editada: KALYAN ACHARJYA
el 13 de Mayo de 2018
Undefined function or variable 'myRK4'? Can you clarify your question?
Which data not showing up, Is this third plot, %excitation?
Susan Santiago
el 13 de Mayo de 2018
Susan Santiago
el 13 de Mayo de 2018
KALYAN ACHARJYA
el 13 de Mayo de 2018

Respuestas (1)
KALYAN ACHARJYA
el 13 de Mayo de 2018
0 votos
% Are you looking for this data

4 comentarios
Susan Santiago
el 13 de Mayo de 2018
Hi Susan,
i couldnt solve your problem until now, but I was able to narrow the problem down a bit. The issue happens when you call the Input argument F of your function:
function [sol_euler3] = myEuler3(F, y0, ti, tf, h)
t = ti:h:tf;
y = zeros(length(y0),length(t));
y(:,1) = y0;
for i = 2:length(t)
% original: y(:,i) = y(:,i-1) + h*F(t(i-1),y(:,i-1));
% works until here: y(:,i) = y(:,i-1) + h;
% doesnt work: y(:,i) = F(t(i-1),y(:,i-1));
end
sol_euler3 = [ t; y ];
end
If you comment out the section "works until here" and execute the code, what you expect happens. However, invoking F (t (i-1), y (:, i-1)) always ends with the result 0, which always results in the result you see because of the multiplication and addition to the previous loop pass.
I'm not sure what you want to achieve when you call F. Anyway, here is your problem. That is also the reason why there is no problem in the function myRK4 - because F does not occur there.
Maybe you can describe what the call of F should actually reach / calculate (Should F (t, y) be the solution of your ode45 calculation?), then somebody here will be able to solve your problem quickly.
Best regards
Stephan
Susan Santiago
el 14 de Mayo de 2018
Hi Susan,
while trying to understand the issue i found that:

_
This is the result of your computation which is working. When i look at the dimensions you calculate i cant believe that this is a correct calculation.
The dimensions explode with each iteration step ending in a range from -2*10e116 up to 5*10e114 (!). Is these order of magnitude actually correct for your problem?
What im still trying to understand is, what F(t,y) is exactly doing (or should do...)
So far I have understood that you call the function Mu via the function handle fMu1, which you give t and y. Furthermore, I believe that you want to evaluate this calculation for a period of 20 seconds every second.
What I did not understand is where the y comes from, that you want to pass the function handle. In addition to the above-mentioned (suspected) problem, there will always be 0, because the function call at time 0 with the y0 = IC equals zero. In the next iteration step, you then evaluate from F (t = 1, y = 1) -> which corresponds to the call of the function of F (1, [0; 0; 0; 0; 0,0]) -> This yields again 0.
Best regards
Stephan
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!