Index must be a positive integer or logical
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
I am getting the following error while running the code:
Attempted to access r(8.5); index must be a positive integer or logical.
Error in L158 (line 15) A(1,1)=r(n+0.5)/(h^2)+r(n-0.5)/(h^2)+a*r(n)
This is the line of code:
h=0.2
n=1.8/h -1
a=1
c=0.25
r=linspace(0.2+h,2,n+1)
A=zeros(n+1,n+1)
b=zeros(n+1,2)
A(1,1)=r(n+0.5)/(h^2)+r(n-0.5)/(h^2)+a*r(n)
Can someone help me with this?
Réponses (1)
Mischa Kim
le 12 Juin 2014
Modifié(e) : Mischa Kim
le 12 Juin 2014
Sebastiaan, the problem is that in
A(1,1) = r(n+0.5)/(h^2)+r(n-0.5)/(h^2)+a*r(n)
you are trying to access
r(8.5) % n = 8
Array indices need to be integers (or logicals, as pointed out in the error msg), so you could use:
A(1,1) = r(n+1)/(h^2)+r(n-1)/(h^2)+a*r(n)
provided it does what you need it to do.
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!