diff options
Diffstat (limited to '50/CH6/EX6.21/ex_6_21.sce')
-rwxr-xr-x | 50/CH6/EX6.21/ex_6_21.sce | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/50/CH6/EX6.21/ex_6_21.sce b/50/CH6/EX6.21/ex_6_21.sce new file mode 100755 index 000000000..32b9e0d95 --- /dev/null +++ b/50/CH6/EX6.21/ex_6_21.sce @@ -0,0 +1,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;
+
|