data not showing up

4 visualizaciones (últimos 30 días)
Susan Santiago
Susan Santiago el 13 de Mayo de 2018
Editada: Stephan el 15 de Mayo de 2018
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
Susan Santiago el 13 de Mayo de 2018
also the third plot, I haven't finished working on which is why it's commented
KALYAN ACHARJYA
KALYAN ACHARJYA el 13 de Mayo de 2018

Iniciar sesión para comentar.

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 13 de Mayo de 2018

% Are you looking for this data

  4 comentarios
Susan Santiago
Susan Santiago el 14 de Mayo de 2018
F is the function being evaluated. it's the same as the function being evaluated with ode45. When the function runs, the results from each method should be similar. How do I still solve using Euler's method while avoiding the issue that you point out?
Stephan
Stephan el 15 de Mayo de 2018
Editada: Stephan el 15 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

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by