0% found this document useful (0 votes)
5 views7 pages

Matlab Algo L6 To L10

The document outlines algorithms for solving algebraic and transcendental equations using the Regula Falsi and Newton-Raphson methods, as well as interpolation techniques using Newton's forward and backward difference formulas. It also describes methods for computing the area under a curve using the Trapezoidal rule, Simpson’s 1/3rd and 3/8th rules, and solving first-order ordinary differential equations (ODEs) using Taylor’s and Modified Euler’s methods, along with the Runge-Kutta and Milne’s methods. Each section includes step-by-step algorithms for implementation.

Uploaded by

harrambandi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

Matlab Algo L6 To L10

The document outlines algorithms for solving algebraic and transcendental equations using the Regula Falsi and Newton-Raphson methods, as well as interpolation techniques using Newton's forward and backward difference formulas. It also describes methods for computing the area under a curve using the Trapezoidal rule, Simpson’s 1/3rd and 3/8th rules, and solving first-order ordinary differential equations (ODEs) using Taylor’s and Modified Euler’s methods, along with the Runge-Kutta and Milne’s methods. Each section includes step-by-step algorithms for implementation.

Uploaded by

harrambandi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

LAB 06

Solution of algebraic and transcendental equations by regula falsi and Newton


Raphson method

i)Regula falsi method

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

ii) Newton raphson method


Algorithm

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

ii)Simpson’s 1/3rd 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:- Assign yj = f(a+i*h)
Step 8:- Calculate the approximation of integral using Simpson’s 1/3rd rule
Step 9:- Print the value of integral

iii)Simpson’s 3/8 th 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:- substitute the values in the function
Step 8 :- Initialize an index vector i form 3 to n-1 with gap 3
Step 9 :- substitute the values in the function
Step 10:-compute sum
Step 11:- delete the values at I position
Step 12:- calculate the integral using simpson 3/8 th rule
Step 13:- display the integral
Step 14:-end

LAB 9
Solution of ODE of first order and first degree by Taylor’s and Modified Euler’s
method

i) Taylor’s method

Algorithm

Step 1:- Start


Step 2:- Define f(x)
Step 3:- Read y1,x0,y0,X,h
Step 4:- Compute first 3 derivatives
Step 5:- Calculate the initial values for y1,y2,y3 and y4 at the initial condition X0 = 0
Y0 = 1
Step 6:- Iterate using loop from X0+h to X
Step 7 :- Calculate using taylor’s series formula
Step 8;- Substitute the x in y
Step 9:- Display the values

ii) Modified Euler’s Method

Algorithm

Step 1:- Start


Step 2:- Define f(x)
Step 3:- Read x0, y0, Xn, h
Step 4:- Print the table header to display X & Y
Step 5:- while X0 < Xn
Step 6:- Calculate using modified Euler’s method
Step 7:- Calculate the error as absolute difference btn correct value and previous
approximation
Step 8:- Update the values
Step 9:- Display the value

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

ii) Milne’s Method

Algorithm

Step 1:- Start


Step 2:- Define F(x,y)
Step 4:- Read x0, x1, x2, x3, x4, h, y0, y1, y2, y3,
Step 5:- Compute the values of y11, y22, y33 by substituting the x & y values in the
function
Step 6:- Compute y4 using the milne’s predictor formula
Step 7:- Calculate M using milne’s corrector formula for more accurate values
Step 8:- Display the values of M

You might also like