Maniruzzaman Akash's Blog

Maniruzzaman Akash, A programmer, A web programmer, a helpful person to share knowledge and everything..

  • Home
  • Programming
    • C Programming
    • Java Programming
    • C++ Programming
    • C# Programming
    • Python Programming
    • Data Structure
  • Web
    • HTML
    • CSS
    • Javascript
    • PHP
    • AJAX
    • XML
  • FrameWork
    • Bootstrap(CSS)
    • Laravel 5(PHP)
  • Database
    • MySQL
    • Oracle
    • SQL Server
  • Android
    • Android Development
  • Mathematics
    • Numerical Methods
  • Others
    • My Articles
    • Download Ebooks
    • Mathematics
    • Difference Between
  • Contact
Numerical Methods

Numerical method Codes simple MatLab implementation

Monday, June 12, 2017 By Maniruzzaman Akash 0 Comments

Numerical method Codes simple MatLab implementation

In this tutorial, we;ll learn about following MAT LAB works of Numerical Methods.

  1. Numerical Method Simpson 1/3 MatLab Code implementation
  2. Numerical Method Simpson 3/8  MatLab Code implementation
  3. Numerical Method Gauss Elimination MatLab Code Implementation
  4. Numerical Method Gauss Elimination MatLab Code Implementation:
  5. Numerical Method Gauss Zordan MatLab Code Implementation
  6. Numerical Method Gauss Cramers Rule MatLab Code Implementation
  7. Numerical Method Newton Raphson MatLab Code Implementation
  8. Numerical Method Fixed Point Iteration MatLab Code Implementation
  9. Numerical Method False Position Method MatLab Code Implementation
  10. Numerical Method Bisection Method MatLab Code Implementation

Numerical Method Simpson 1/3 MatLab Code implementation:


f = @ (x)  .2+ 25*x - 200*x^2+675*x^3-900*x^4+400*x^5;
a = 0;
b = 0.8;
x0 = a; 
x1 = (b-a)/2; 
x2 = b; 

fx0 = feval(f,x0);
fx1 = feval(f,x1);
fx2 = feval(f,x2);
exact_integral = 1.640533;

I = ((fx0 + (4*fx1) + fx2)/6 * (b-a));

E = abs((exact_integral - I)/exact_integral) * 100;


fprintf('\nIntegral = %f\n', I);
fprintf('\nError = %f\n', E);


Numerical Method Simpson 3/8  MatLab Code implementation:

f = @ (x) 0.2 + 25*x - 200*(x^2) + 675*(x^3) -900*(x^4) + 400*(x^5);

a = 0;
b = .8;

x0 = a;
x1 = (b-a)/3;
x2 = 2 * x1;
x3 = b;

fx0 = feval(f, x0);
fx1 = feval(f, x1);
fx2 = feval(f, x2);
fx3 = feval(f, x3);

I = (b - a) * ((fx0 + 3*(fx1 + fx2) + fx3)/8);

exact_integral = input('Enter Exact Integral : ');
E = abs((exact_integral - I)/exact_integral) * 100;


fprintf('\nIntegral = %f\n', I);
fprintf('\nError = %f\n', E);



Numerical Method Gauss Elimination MatLab Code Implementation:

%% Gauss Elimination Problem

% x1   + x2   + x3  = 4
% 2x1  + x2   + 3x3 = 7
% 3x1  + 4x2  - 2x3 = 9


n = 3;   %Solve 3 equestion here

Ab = [1 1 1 4; 2 1 3 7; 3 4 -2 9];

%% Forward Substitution
% Rj = Rj - ai,j*Ri Where ai,j = A(j,i)/A(i,i)


% A(1, 1)
alpha = Ab(2, 1)/Ab(1, 1);
Ab(2, :) = Ab(2, :) - alpha*Ab(1, :);

alpha = Ab(3, 1)/Ab(1, 1);
Ab(3, :) = Ab(3, :) - alpha*Ab(1, :);

% A(2, 2)
alpha = Ab(3, 2)/Ab(2, 2);
Ab(3, :) = Ab(3, :) - alpha*Ab(2, :);


%% Backward Substitution

x = zeros(n, 1);
x(3) = Ab(3, end) / Ab(3,3);
x(2) = (Ab(2, end) - Ab(2, 3) * x(3)) / Ab(2, 2);
x(1) = (Ab(1, end) - (Ab(1, 2) * x(2) + Ab(1, 3)*x(3))) / Ab(1, 1);

% Different Solution using loop
% for i= n:-1:1
%     x(i) = (Ab(i, end) - Ab(1, i+1:n) * x(i+1:n)) / Ab(i, i);
% end

disp('Final Answer');
fprintf('\nx1 = %.4f\nx2 = %.4f\nx3 = %.4f\n', x(1), x(2), x(3));


Numerical Method Gauss Zordan MatLab Code Implementation:

M = [3 -.1 -.2 7.85; .1 7 -.3 -19.3; .3 -.2 10 71.4];

disp('Start Matrix :')
disp(M);
for r =1:3
    
    A = M(r, :);
    A = A/A(r);
    M(r, :) = A;    %Set matrix from A For row 1
    
    for s=1:3
        if r~=s
            M(s, :) =  M(s, :) -  M(r, :) * M(s, r);
        end
    end
end

disp('Final Matrix :')
disp(M);
disp('Solution :')

%disp(M(:,4))
fprintf('X = %.4f\n', M(1, 4))
fprintf('Y = %.4f\n', M(1, 4))
fprintf('Z = %.4f\n', M(1, 4))


Numerical Method Gauss Cramers Rule MatLab Code Implementation:

%Cramers Rule Problems
% Use cramer rules to solve the problem
% .3x1 + .52x2 + x3     = -.01
% .5x1 + x2    + 1.9x3  = .67
% .1x1 + .3x2  + .5x3   = -.44

det_M = [.3 .52 1; .5 1 1.9; .1 .3 .5 ];
determinant = det(det_M);

det_x1 = [-.01 .52 1; .67 1 1.9; -.44 .3 .5 ];
x1 = det(det_x1) / determinant;


det_x2 = [.3 -.01 1; .5 .67 1.9; .1 -.44 .5 ];
x2 = det(det_x2) / determinant;

det_x3 = [.3 .52 -.01; .5 1 .67; .1 .3 -.44 ];
x3 = det(det_x3) / determinant;


disp('Solutions');
fprintf('x1 = %.2f\n', x1);
fprintf('x2 = %.2f\n', x2);
fprintf('x3 = %.2f\n', x3);

%disp(determinant)


Numerical Method Newton Raphson MatLab Code Implementation:

%Function e^-x
f = @ (x)  exp(-x);
f1 = @ (x)  -exp(-x);

x0 = 0;         %Given

for i=1:10
    y = x0 - ((feval(f, x0))/(feval(f1, x0)));
    x0 = y;
    fprintf('\nStep %d Result %.4f\n', i, y);
end

fprintf('\nResult of Newton Raphson : %f', y);



Numerical Method Fixed Point Iteration MatLab Code Implementation:

%Function e^-x
f = @ (x)  exp(-x);

x0 = 0;
result = 0;

for i=1:10
    result = feval(f, x0);
    x0 = result;
    fprintf('Step %d Result %.4f\n', i, result);
end

fprintf('\nResult is : %f', result);


Numerical Method False Position Method MatLab Code Implementation:

%Function
f = @(x) 5 * x^4 - 2.7 * x^2 - 2*x + 0.5;
l = input('Enter Lower Limit : ');
u = input('Enter Upper Limit : ');
previous_approximation = 0;

f_l = feval(f, l);
f_u = feval(f, u);
root = u -((f_u * (l-u))/ (f_l - f_u));
given_absoulte_error = input('Enter absolute error : ');
absolute_error = abs((root - previous_approximation) / root ) * 100;
previous_approximation = root;

while(absolute_error > given_absoulte_error)
    f_l = feval(f, l);
    f_u = feval(f, u);
    f_root = feval(f, root);
    
    if(f_l * f_root > 0)
        l = root;
    else
        u = root;
    end;
    
    f_l = feval(f, l);
    f_u = feval(f, u);
    
    
    root = u -((f_u * (l-u))/ (f_l - f_u));
    absolute_error = abs((root - previous_approximation) / root ) * 100;
    previous_approximation = root;
    
    fprintf('Root %f Error %f\n', root, absolute_error);
    
end;

disp('-------------------------------');
fprintf('Final Root = %f and absolute error = %f', root, absolute_error);

Numerical Method Bisection Method MatLab Code Implementation:

f = @(x) x^2 - 3;
l = input('Enter Lower Limit : ');
u = input('Enter Upper Limit : ');
prev_approximation = 0;

root = (l + u)/2;
f_root = feval(f, root);
given_absoulte_error = input('Enter absolute error : ');
absolute_error = abs((root - prev_approximation) / root) * 100;
disp(absolute_error);

fprintf('\nStep a\tb\tf(a)\tf(b)\troot\tError_abs\n');
while(absolute_error > given_absoulte_error)
    f_root = feval(f, root);
    f_l = feval(f, l);
    f_u = feval(f, u);
    
    if(f_l * f_root > 0)
        l = root;
    else
        u = root;
    end;
    
    root = (l + u)/2;
    absolute_error = abs((root - prev_approximation) / root) * 100;
    prev_approximation = root;
    
    fprintf('Step %f Error %f\n', root, absolute_error);
    fprintf('\nStep a\tb\tf(a)\tf(b)\troot\tError_abs\n');
    
end;

disp('-------------------------------');
fprintf('Final Root = %f and absolute error = %f', root, absolute_error);



Tags: 

Numerical method Codes simple MatLab implementation, Numerical Method Gauss Elimination Matlab code, Numerical Method Gauss Zordan Matlab code, Numerical Method Newton Raphson code, Numerical Method Cramers Rules Matlab code, Numerical Method Simpson 1/3 MatLab Code implementation.Numerical Method Simpson 3/8  MatLab Code implementation.Numerical Method Gauss Elimination MatLab Code Implementation.Numerical Method Gauss Elimination MatLab Code Implementation:.Numerical Method Gauss Zordan MatLab Code Implementation.Numerical Method Gauss Cramers Rule MatLab Code Implementation.Numerical Method Newton Raphson MatLab Code Implementation.Numerical Method Fixed Point Iteration MatLab Code Implementation.Numerical,Method False Position Method MatLab Code Implementation,Numerical Method Bisection Method MatLab Code Implementation



Numerical Methods
Share:

Maniruzzaman Akash
Maniruzzaman Akash, an enthusiastic programmer, a web developer

Related Articles


0 comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments ( Atom )

Popular Posts

  • Numerical Methods 20 Multiple Choice Questions and Answers
  • Consider a hypothetical 32-bit microprocessor having 32-bit instructions: Solutions
  • List and briefly define two approaches to dealing with multiple interrupts
  • The hypothetical machine has two I/O instructions: 0011= Load AC fro I/O 0111= Store AC to I/O Solutions
  • What are the characteristics of Digital IC's?-Solution
  • Mid Square Method Code implementation in C and MatLab
  • List and briefly define the possible states that define an instruction execution
  • BFS, DFS, DLS in Tree implementation in C
  • Download Laravel Offline Documentation as HTML
  • Simpson's 1/3 Code in Matlab

Category

Advanced PHP Android Developement Articles Artificial Intelligenece Blogger Tips Blogging Career Bootstrap Offline Documentation Bootstrap Templates C Programming Computer Architecture Data Structure Difference Between Download Documentation Download Ebook Download Free Blog Template Earning Money Electrical Electronics Guest Posts HTML Java Programming Laravel Laravel Bangla Tutorial MatLab Code My Videos MySQL Database Numerical Methods Offline Documentation Recent Topics Simulation and Modeling Unity Game Development Web Design Web Development

LIKE ME ON FACEBOOK

TAGS

  • Advanced PHP (3)
  • Android Developement (5)
  • Articles (6)
  • Artificial Intelligenece (3)
  • Blogger Tips (5)
  • Blogging Career (1)
  • Bootstrap Offline Documentation (1)
  • Bootstrap Templates (1)
  • C Programming (14)
  • Computer Architecture (5)
  • Data Structure (11)
  • Difference Between (1)
  • Download Documentation (2)
  • Download Ebook (3)
  • Download Free Blog Template (2)
  • Earning Money (1)
  • Electrical Electronics (1)
  • Guest Posts (1)
  • HTML (4)
  • Java Programming (2)
  • Laravel (3)
  • Laravel Bangla Tutorial (1)
  • MatLab Code (2)
  • My Videos (3)
  • MySQL Database (7)
  • Numerical Methods (9)
  • Offline Documentation (1)
  • Recent Topics (1)
  • Simulation and Modeling (2)
  • Unity Game Development (3)
  • Web Design (3)
  • Web Development (1)

Join Google+

Maniruzzaman Akash
View my complete profile

Join With Me

Site Visitors

Best Sites For a programmer

  • URI Online Judge Solution By Me
  • StackOverFlow
  • W3 School
  • Git Hub - Store your Every Document

Popular Posts

  • What are the characteristics of Digital IC's?-Solution
  • The hypothetical machine has two I/O instructions: 0011= Load AC fro I/O 0111= Store AC to I/O Solutions
  • Consider a hypothetical 32-bit microprocessor having 32-bit instructions: Solutions
  • Mid Square Method Code implementation in C and MatLab
  • How to import Excel,CSV file in Laravel And insert data in database
  • Numerical Methods 20 Multiple Choice Questions and Answers
  • How to browse files on Android outside of Unity app folder
  • Depth First Search DFS code using Binary Tree in C language
  • Numerical method Codes simple MatLab implementation
  • ফিফা ওয়ার্ল্ড কাপ ২০১৮ শিডিউল এবং সমস্ত আপডেট- FIFA World Cup 2018 - Bangladesh Time Schedule

Earn Money From Your site

Translate To your language

Categories

Advanced PHP (3) Android Developement (5) Articles (6) Artificial Intelligenece (3) Blogger Tips (5) Blogging Career (1) Bootstrap Offline Documentation (1) Bootstrap Templates (1) C Programming (14) Computer Architecture (5) Data Structure (11) Difference Between (1) Download Documentation (2) Download Ebook (3) Download Free Blog Template (2) Earning Money (1) Electrical Electronics (1) Guest Posts (1) HTML (4) Java Programming (2) Laravel (3) Laravel Bangla Tutorial (1) MatLab Code (2) My Videos (3) MySQL Database (7) Numerical Methods (9) Offline Documentation (1) Recent Topics (1) Simulation and Modeling (2) Unity Game Development (3) Web Design (3) Web Development (1)

Subscribe To This Site To Get Latest Article On Programming or web

Posts
Atom
Posts
Comments
Atom
Comments
© 2016 Maniruzzaman Akash's Blog | All rights reserved
Developed By Maniruzzaman Akash Created By Responsive Blogger Templates | Distributed By Gooyaabi Templates