필터 지우기
필터 지우기

Array indices must be positive or logical values

조회 수: 1 (최근 30일)
Patrick Scott
Patrick Scott 2021년 2월 27일
답변: Steven Lord 2021년 2월 27일
I am trying to conduct Implicit Midpoint and I am getting stuck. Why does this error appear? It is also coming up for my Adams-Bashforth.
clc
clear
close all
f= @(x,y)(-50*(y-cos(x)));
N = 100;
T = 1;
y0 = 0;
h = T/N;
x= (0:h:1);
y = zeros(N+1,1);
y(1) = y0;
for i = 1:N
j = i+0.5
y(i+1) = y(i) + h*f(x(j), y(j));
end

답변 (1개)

Steven Lord
Steven Lord 2021년 2월 27일
for i = 1:N
j = i+0.5
y(i+1) = y(i) + h*f(x(j), y(j));
end
There's no such thing as the 1.5th element of either x or y in MATLAB, which is what you're trying to use as inputs to f on the third line of this code segment. Numeric indices must be real positive finite integer values.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by