Numerical Analysis Sessional: Hafijur Rahman
Numerical Analysis Sessional: Hafijur Rahman
Numerical Analysis Sessional: Hafijur Rahman
Lecture 1
by Hafijur Rahman
ME 262
7/3/2014 1
Tentative Schedule
Class TOPICS
1 Introduction: MATLAB
2 Root Finding
3 Solution of Linear and Non-linear Algebraic Equations
4 Curve Fitting and Numerical Interpolation
5 Numerical Differentiation and Integration
6 Solution of Differential Equations
7 Final Quiz
7/3/2014
2
2
MATLAB windows
7/3/2014 3
Some Features about MATLAB
Never have to worry about data type or the
data object declarations. No need to initialize
variables.
MATLAB automatically sets the value to be
double (real).
Dimensioning is automatic in MATLAB.
MATLAB is case sensitive.
7/3/2014 4
MATLAB vs C
sum=0;
for i=1:1:10
sum=sum+i;
end
disp(sum);
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum;
clrscr();
sum=0;
for(i=1;i<=10;i++)
{sum=sum+i;
}
printf("%d",sum);
getch();
}
7/3/2014 5
Customization
File Preference
Allows you personalize your MATLAB experience
7/3/2014 6
Scripts: Overview
Scripts are
collection of commands executed in sequence
written in the MATLAB editor
saved as MATLAB files (.m extension)
7/3/2014 7
3 July 2014 8 ME262 Numerical Analysis Sessional
Text Input & Output
3 July 2014 9 ME262 Numerical Analysis Sessional
Text Output with disp
Take values of three different variables as input and
display their summation
3 July 2014 10 ME262 Numerical Analysis Sessional
Prompting for User Input
function [x, y, z] = newfunc (a, b)
x = a + b; y = a b; z = a * b;
3 July 2014 11 ME262 Numerical Analysis Sessional
Function .m File
function noarg();
x=6;
disp(x);
Function name should match MATLAB file name
More about function
Find f(x) of an real number x which is taken as input
function value should be calculated in a separate .m file
f(x)=x
2
-6x+15
function s=f(x)
s=x^2-6*x+15;
f.m command window
>> f (input('Enter value x = '))
Enter value x = 5
10
3 July 2014 12 ME262 Numerical Analysis Sessional
function [x, y, z] = newfunc (a, b)
x = a + b; y = a b; z = a * b;
a=input('input the value of a=');
b=input('input the value of b=');
[x y z]=newfunc(a,b);
disp([x y z]);
3 July 2014 13 ME262 Numerical Analysis Sessional
Relational Operators
3 July 2014 14 ME262 Numerical Analysis Sessional
Relational Operators
3 July 2014 15 ME262 Numerical Analysis Sessional
Logical Operators
7/3/2014 16
Hope that wasnt too much!!