MATLAB Answers

Error in Euler's method code.

조회 수: 1(최근 30일)
Mike Asmanis
Mike Asmanis 2021년 6월 18일
답변: Claire Fan 2021년 6월 18일
Why am I getting Error:Invalid array indexing?I need help in order to code it correctly , I am a newbie.
% Euler
% y'(t)=cos(t+y) με y(0)=0
clc
clear all
close all
h=0.01;
N=100; % number of steps
y(0)=0;
for n=1:N
y(n+1)=y(n)+h*((cos(t+y)(n)));
t(n+1)=t(h+1);
end
hold on
t=0:0.01:3;
y=(-t)+2*atan(t); % exact solution
plot(t,y)

답변(1개)

Claire Fan
Claire Fan 2021년 6월 18일
matlab is an one-based array indexing programming language, hence array indices must be positive integers.

Community Treasure Hunt

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

Start Hunting!

Translated by