- You cannot use pit , you have to specify as pi*t
- Since you define t(1)=a (whose value is 0), y(t) is referring to y(0). In MATLAB indexing starts from 1. So y(0) is erroneous.
Euler's, Improved Euler's, and Runge Kutta code
11 ビュー (過去 30 日間)
I am new to MatLab and I have to create a code for Euler's method, Improved Euler's Method and Runge Kutta with the problem ut=cos(pit)+u(t) with the initial condition u(0)=3 with the time up to 2.0. I need to graph the solution vs. the exact solution, and a graph of the errors for number of points N=10,20,40,80,160,320,640. I have started the Euler's code but I keep getting undefined function or variable y
clear t % Clears old time steps and
clear y % y values from previous runs
a=0; % Initial time
b=2; % Final time
N=[10 20 40 80 160 320 640]; % Number of time steps
y=3; % Initial value y(a)
t(1)=a;% Time step
for i=1: N(n)
title(['Question 1 Euler Method' , name,])
legend('N=10', 'N=20','N=40', 'N=80', 'N=160', 'N=320', 'N=640')
回答 (1 件)
Jyotish Robin 2017 年 10 月 13 日
I just had a quick look at your code and there are a few issues that I would like to point out as follows:
In general , I would suggest you to look through MATLAB documentation to understand these things better.
For example, https://www.mathworks.com/help/matlab/math/matrix-indexing.html talks about Matrix indexing in MATLAB.
Hope the above suggestions help!