Download - Numerical Operations
![Page 1: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/1.jpg)
Numerical Operations
S. Awad, Ph.D.
M. Corless, M.S.E.E.
E.C.E. Department
University of Michigan-Dearborn
Introduction to Matlab:
Numerical Interpolation
![Page 2: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/2.jpg)
2
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
Interpolation Topics
1D Interpolation Interp1 Command Spline Command 2D Interpolation Interp2 Command
![Page 3: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/3.jpg)
3
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
1-D Interpolation
Given xdata and ydata
Want to estimate the values of the function: xi=[xi(1) xi(2) … ]’ % values of x
The command interp1 is used for One Dimensional Interpolation
![Page 4: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/4.jpg)
4
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
interp1 Command
yi=interp1(xdata,ydata,xi,method)
Where the method of interpolation can be:
‘linear’ for linear interpolation ‘spline’ for Spline Interpolation ‘cubic’ for Cubic Interpolation
![Page 5: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/5.jpg)
5
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
A Coarse Sine Wave
» xdata=[0:pi/4:2*pi]';
» ydata=sin(xdata);
» plot(xdata,ydata);
» title('Course
Sine Wave');
» xlabel('xdata');
» ylabel('ydata');
![Page 6: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/6.jpg)
6
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
Interpolated Sine Wave
» xi=[0:pi/64:2*pi]';
» yi=interp1(xdata,
ydata,xi,'spline');
» plot(xi,yi)
» title('Interpolated
Sine Wave');
» xlabel('xi');
» ylabel('yi');
![Page 7: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/7.jpg)
7
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
Good Fit & Error Check for Good Fit
» plot(xi,sin(xi),'r',xi,yi,'x');
Check For Error
» plot(xi,(yi-sin(xi)));
![Page 8: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/8.jpg)
8
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
Spline Use spline for a cubic spline interpolation method
» yi=spline(xdata,ydata,xi);
» plot(xi,yi);
» title('Cubic Spline
Interpolation');
» xlabel('xi');
» ylabel('yi');
![Page 9: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/9.jpg)
9
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
2-D Interpolation Consider the following sheet of metal with the
following temperatures at different points:
1 2 3 4 5 x1 82° 81° 80° 82° 84°2 79° 63° 61° 65° 81°3 84° 84° 82° 85° 86°
y
We will estimate the temperatures on a finer scale
![Page 10: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/10.jpg)
10
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
Plot Original Mesh Set up Matrices in Matlab
» z=[82 81 80 82 84
79 63 61 65 81
84 84 82 85 86];
» xdata =[1:5];
» ydata=[1:3]';
Plot the Original Mesh
» mesh(xdata,ydata,z);
» title('Original Metal Temps');
» zlabel('temp');
![Page 11: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/11.jpg)
11
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
Original Mesh
Course Concave
![Page 12: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/12.jpg)
12
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
Finer 2-D Interpolation Estimate Temperature Surface to a finer scale using the interp2 command
» xi=[1:0.1:5];
» yi=[1:0.2:3]';
» zi=interp2(xdata,ydata,z,xi,yi,'cubic');
% or ‘linear’ or ‘spline’
» mesh(xi,yi,zi);
» title('2D Interp Metal Temps');
» zlabel('temp');
![Page 13: Numerical Operations](https://reader035.vdocument.in/reader035/viewer/2022070407/5681433c550346895dafb0c1/html5/thumbnails/13.jpg)
13
Numerical Operations:U of M-Dearborn ECE DepartmentIntroduction to MATLAB and its Toolboxes
Interpolation
2-D Interpolated Mesh
Smooth Concave