summaryrefslogtreecommitdiff
path: root/50/CH6/EX6.21/ex_6_21.sce
blob: 32b9e0d95372563ab6c7252d76c7e240e48eb20c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// example  no. 6.21,
// caption: solving the IVP by implicit RK2 method 

// u'=f(t,u)
// u'=-2tu^2
//u(0)=1,h=0.2;
t0=0;h=0.2;tn=.4;u0=1;
deff('[z]=f(t,u)','z=-2*t*u^2');
umaxAllowed = 1e+100;

t = [t0:h:tn]; u = zeros(t); n = length(u); u(1) = u0;

for j = 1:n-1
   // k1=h*f(t(j)+h/2,u(j)+k1/2);
	// conidering the IVP we can infer that the above expression in non linear in k1,
// hence we use newton rapson method to solve for k1;
deff('[w]=F(u2)','w=k1+h*(2*t(j)+h)*(u(j)+k1/2)^2')    // u2=u(2)
deff('[x]=Fp(u2)','x=1+h*(2*t(j)+h)*(u(j)+k1/2)')

k1=h*f(t(j),u(j));

newton(k1,F,Fp);
   u(j+1) = u(j) +k1
   disp(u(j+1))
	
end;