The MATLAB functions "linearShooting.m", "nonlinearShooting.m", "nf1.m", and "nf2.m" are on the course
website. In the homework, you need to show all other functions that you defined using MATLAB.
function problem2_11_1
f1=inline('[u(2), u(2)+2*u(1)+cos(x
> error=test(0.1,1-exp(-0.1)
error =
0
0.3500
0
0.0006
1.0858
0.0030
3.3636
function [c,E]=least2(x,y,n)
for j=1:n+1
A(:,j)=x'.^(j-1);
end
c=(A'*A)\(A'*y');
E=sum(A*c-y').^2);
figure
plot(x,y,'r.')
hold on
z=linspace(min(x),max(x);
pval=zeros(size(z);
for
Only 3-step and 4-step methods are required for #1(c) and #4(c).
#5 (c):
function [t,w]=PredictorCorrector4(a,b,alpha,h,f)
N=ceil(b-a)/h);
t=zeros(1,N+1);
w=zeros(1,N+1);
F=zeros(1,N+1);
t(1)=a;
w(1)=alpha;
% RK4
for i=1:3
F(i)=f(t(i),w(i);
K1=h*F(i);
K2=
#11 (a): The MATLAB function Euler.m is the same as in #10(a).
Commands and results in the main window:
> f=inline('-y+t+1','t','y');
> [t,w1]=Euler(0,5,1,0.2,f);
> [t,w2]=Euler(0,5,1,0.1,f);
> [t,w3]=Euler(0,5,1,0.05,f);
> [w1(end), w2(end), w3(end)]
ans