What wrong in line 12 ?? help me please (Index exceeds matrix dimensions.)

조회 수: 4 (최근 30일)
Bui Thien Phuc
Bui Thien Phuc 2019년 4월 9일
편집: Torsten 2019년 4월 10일
clear
close all;
N=10;
h = 0.5;
u1(1)= 2 ;
u2(1)= 3 ;
u3(1)=0 ;
t(1) = 0;
for n=1:N
u3(n+1)=u1(n)+h*u2(1);
u1(n+1)=u1(n)+1/2*(4*exp(0.8*t(n))-0.5*u1(n)+4*exp(0.8*t(n+1))-0.5*u3(n));
t(n+1)= t(n) + h ;
end
plot(t,u1);

답변 (2개)

Alex Mcaulley
Alex Mcaulley 2019년 4월 9일
In this line:
u1(n+1)=u1(n)+1/2*(4*exp(0.8*t(n))-0.5*u1(n)+4*exp(0.8*t(n+1))-0.5*u3(n));
the length of t is n, then t(n+1) gives an error
  댓글 수: 6
Bui Thien Phuc
Bui Thien Phuc 2019년 4월 9일
just answer me I want to use u2(1) only one time in first circle so I did right ?
Torsten
Torsten 2019년 4월 10일
편집: Torsten 2019년 4월 10일
If you use your code: no.
If you use Alex's second code: yes.

댓글을 달려면 로그인하십시오.


Torsten
Torsten 2019년 4월 9일
clear
close all;
N = 10;
h = 0.5;
u1(1) = 2 ;
u2(1) = 3 ;
u3(1) = 0 ;
t = 0:h:N*h;
for n = 1:N
u3(n+1) = u1(n)+h*u2(1);
u1(n+1) = u1(n)+1/2*(4*exp(0.8*t(n))-0.5*u1(n)+4*exp(0.8*t(n+1))-0.5*u3(n));
end
plot(t,u1);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by