Milne
Milne
clear;
clc;
f = input('Enter your dy/dx : \n'); %Enter the Function with @(x,y)
x0 = input('Enter the Initial Value of x : \n');
y0 = input('Enter the Initial Value of y : \n');
xn = input('Enter the Value of x at which y is to be Calculated : \n');
h = input('Enter the Step Size :\n');
n = (xn-x0)/h;
%Runge-Kutta Method
for i = 1:4
k1 = h*f(x0(i),y0(i));
k2 = h*f(x0(i)+(h/2),y0(i)+(k1/2));
k3 = h*f(x0(i)+(h/2),y0(i)+(k2/2));
k4 = h*f(x0(i)+h,y0(i)+k3);
yn(i) = y0(i) + (1/6)*(k1+(2*k2)+(2*k3)+k4);
x0(i+1) = x0(i) + h;
y0(i+1) = yn(i);
end
%Milne's Mathod
for i = 1:4
F(i) = f(x0(i),y0(i));
end
for i = 5:n+1
y0(i) = y0(i-4) + (4*h/3)*(2*F(i-3)-F(i-2)+2*F(i-1))
%Predictor Formula
F(i) = f(x0(i),y0(i))
y0(i) = y0(i-2) + (h/3)*(F(i-2)+4*F(i-1)+F(i))
%Corrector Formula
x0(i+1) = x0(i) + h
end
fprintf('The Solution is : %f\n',y0(n+1))
OUTPUT
%Program:2
%Find Divergence of f = xi + 2*y^2 + 3*z^3k
syms x y z
F = [x 2*y^2 3*z^3];
V = [x y z];
dF = divergence(F,V)
%Program:3
%Find Curl of x^3*y^2*z+y^3*z^2*x+z^3*x^2*y
syms x y z
F = [x^3*y^2*z, y^3*z^2*x, z^3*x^2*y];
V = [x y z];
CV = curl(F,V)
%Program:4
%Prove that F = (x+3y)i + (y-2z)j + (x-2z)k is Solenoidal
syms x y z
F = [x+3*y y-2*z x-2*z];
V = [x y z];
dF = divergence(F,V)
%Program:5
%Prove that vector F = (2*x*y^3*z^4)i + (3*x^2*y^2*z^4)j + (4*x^2*y^3*z^3)k
%is irrotational.
syms x y z
F = [2*x*y^3*z^4, 3*x^2*y^2*z^4, 4*x^2*y^3*z^3];
V = [x y z];
CV = curl(F,V)
OUTPUT
3*y^2 + 3*x*z
3*z^2 + 3*x*y
dF = 9*z^2 + 4*y + 1
CV = x^2*z^3 - 2*x*y^3*z
x^3*y^2 - 2*x*y*z^3
- 2*x^3*y*z + y^3*z^2
dF = 0
CV = 0
0
syms x y
F = input('Enter the vector field in the form [M N] :');
y1 = input('Enter the first curve in terms of x :');
y2 = input('Enter the second curve in terms of x :');
x_ip = input('Enter the x limit in the form [x1 x2] :');
dy = diff(y1,x);
f = subs(F, y,y1);
integrand1 = f(1,1)+f(1,2)*dy;
I1 = int(integrand1,x,x_ip(1,1),x_ip(1,2))
y2 = x^2;
f = subs(F,y,y2);
dy = diff(y2,x);
integrand2 = f(1,1)+f(1,2)*dy;
I2 = int(integrand1,x,x_ip(1,2),x_ip(1,1))
%Result
disp('LHS of greens theorem I1 +I2');
LHS = I1 +I2
M = F(1);
N = F(2);
f = diff(N,x) - diff(M,y);
ymin=y1;
ymax=y2;
xmin=x_ip(1,1);
xmax=x_ip(1,2);
RHS = int(int(f,y,ymin(1),ymax(1)),x,xmin(1),xmax(1));
disp('RHS of greens theorem I1 +I2');
RHS
if LHS==RHS
disp('LHS=RHS')
disp('hence, the Greens Theorem is verified')
end
OUTPUT
I1 = (y*(2*y + 1))/2
I2 = -(y*(2*y + 1))/2
LHS = 0
%Runge-Kutta Method
for i = 1:4
k1 = h*f(x0(i),y0(i));
k2 = h*f(x0(i)+(h/2),y0(i)+(k1/2));
k3 = h*f(x0(i)+(h/2),y0(i)+(k2/2));
k4 = h*f(x0(i)+h,y0(i)+k3);
yn(i) = y0(i) + (1/6)*(k1+(2*k2)+(2*k3)+k4);
x0(i+1) = x0(i) + h;
y0(i+1) = yn(i);
end
sol = [x0',y0']
plot(x0,y0)
title('Solution curve')
OUTPUT
sol = 0 1.0000
0.1000 1.1103
0.2000 1.2428
0.3000 1.3997
0.4000 1.5836