Matlab Algo L6 To L10
Matlab Algo L6 To L10
Algorithm
Step1:- Start
Step2:- Read f, a, b, n, e.
Step3:- if f(a)*f(b)<0 && a<b
Step4:- iterate i using
For I = 1:n
c = (a*f(b)-b*f(a))/(f(b)-f(a))
fprintf(‘c%d=%.4\n’,i,c)
Step5:- if f(a)*f(c)<0
b=c
elseif f(b)*f(c)<0
a=c
Step6:- end the loops
Step7:- print the roots of equation
Step8:- else
Print no roots between the given interval
end
Step1:- Start
Step2:-read f, df, e, x0, n.
Step4:- if df(x0) ~= 0
Step5:- iterate i
for i=1:n
x1 =x0-f(x0)/df(x0)
fprint(‘x%d=%.4f\n’,i,x)
Step6:- if abs(x1-x0)<e
Break
end
Step7:- if df(x1) == 0
Disp(‘N – R method failed’)
end
Step8:- x0 = x1
Step9:- print the roots of the given equations
Step10:- else
Print N-R method failed
end
Lab 07
Interpolation using Newton’s forward and backward difference formula
i)Forward interpolation
Algorithm
Step 1:- Start
Step 2:- Read X, Y, n, d, h, xf
Step 3:- Calculate normalized difference P = (xf-x(1))/h
Step 4:- Calculate 1st forward differences
for k = 2:n
d(k-1,1) = y(k)-y(k-1)
end
Step 5:- Compute further all forward differences
for k=1:n-1
for k=1:n-r
d(k,r)=d(k+1,r-1)-d(k,r-1);
end
end
Step 6:- Display the difference table
Step 7:- Initialize s, t.
Step 8:- Compute the values using newton interpolation formula
Step 9:- Display the interpolated values
Lab 08
Computation of area under the curve using Trapezoidal, Simpson’s 1/3rd
and 3/8th rule
i)Trapezoidal rule
Algorithm
Step 1:- Start
Step 2:- Read a, b, h
Step 3:- Define f(x)
Step 4:- Calculate h = (b-a)/h
Step 5:- Create vectors xi and yi at subinterval endpoints
Step 6:- Initialize an index vector i form 1 to n-1
Step 7:- Calculate the approximation of integral using trapezoidal rule
Step 8:- Print the value of integral
LAB 9
Solution of ODE of first order and first degree by Taylor’s and Modified Euler’s
method
i) Taylor’s method
Algorithm
Algorithm
LAB 10
Solution of ODE of first order and first degree by Runge Kutta 4th order and Milne’s
predictor & corrector method
i) R K Method
Algorithm
Step 1:- Start
Step 2:- Define F(x)
Step 3:- Read x, y, h, X
Step 4:- Compute k1, k2, k3, k4 using for loop
Step 5:- Using RKM formula compute y
Step 6:- display the values of y
Algorithm