Download - Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 [email protected]
![Page 1: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/1.jpg)
Programming with MATFOR 3
吳衍憲 Randy Wu
Application Engineer
(02)8923-5411~13
http://www.ancad.com
![Page 2: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/2.jpg)
Introduction to MATFOR
Programming with MATFOR 3
![Page 3: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/3.jpg)
What Is MATFOR
The advanced visualization toolkit built on Fortran
and C++ specifically designed for programmers in
scientific computing field.
A collection of high-level graphical procedures
developed with the mission of accelerating your
program developing process.
Reinforcing the perception of your simulation
models with enhanced visualization and animation
capabilities.
![Page 4: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/4.jpg)
MATFOR is based on industry recognized visualization li
braries VTK (Visual Tool Kit) , OpenGL and numerical lib
rary Intel MKL (Maths Kernel Library)
MATFOR
Graphics LibraryGraphics Library Numerical LibraryNumerical Library
VTK OpenGL Intel MKL
MATFOR’s Structure
![Page 5: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/5.jpg)
MATFOR Procedures
MATFOR F-Matrix Library contains many procedures. They are divided into several modules as follows:
mod_ess: mfArray query and manipulation
mod_ops: mfArray operators
mod_elfun: elementary functions such as trigonometry, exponential, complex, rounding and remainder
mod_elmat: elementary matrices such as matrix constructors and manipulation functions
mod_matfun: Functions for Linear Algebra
All of them are in fml module.
![Page 6: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/6.jpg)
MATFOR Procedures
MATFOR F-Graphic Library contains many procedures. They are divided into several parts as follows:
FigureWindow FrameDisplayRecording
Plot Creation and ControlPlot Annotation and AppearanceAxis ControlObject ManipulationCamera Manipulation
Linear GraphsSurface GraphsSlice GraphsStreamline Graphs
All of them are in fgl module.
Triangular Surface Graphs Unstructures Grids Unstructured Point Set Velocity Vectors
Image Elementary 3D Objects
Property Setting Simple GUI
![Page 7: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/7.jpg)
Content
What is mfArray
Quick Start (Fortran & C++)
Numerical Library
Graphic Viewer
Data Viewer
Graphic Library
Utilities
Q&A
![Page 8: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/8.jpg)
What is mfArray
an advanced dynamic array defined by MATFOR using OOP features of Fortran 90 (modules, function overloading, derived data type and operators, dynamic storage and pointers)
contains a collection of values and descriptors.
each element holds a value in the same data type as the mfArray
data type and dimensioning are automatically updated.
data typeshape
Descriptors
status flags
mfArray
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 9: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/9.jpg)
mfArray Declarations
Step 1. Add the statement use <module name> add the statement under your program name, module name, function name or procedure name.
you can use either fml, fgl and mod_ess modules.
Step 2. Declare mfArrayAdd your mfArray declare statement under the implicit none declaration.
General format: type(mfArray) ::< variable-list> [ =< value > ]
Example: Program Test
use fml ! Use module fmlimplicit nonetype(mfArray) :: a ! Declare mfArray aa = mfMagic(3) ! Constructs mfArray a
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 10: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/10.jpg)
mfArray works with three broad classes of object types,
character;boolean;numeric.
all data are stored as double precision real, double precision complex or character.
mfArray Intrinsic Data Type
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 11: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/11.jpg)
mfArray Initialization
mfArray accepts the following data types as input:character :: AnCAD ! Lettercharacter(Len=12) :: name ! String logical :: OnTime ! .true. or .false.real (4) :: distance ! 1.0real (8) :: pi ! 3.141819….complex(4):: view ! 2.0 + 3.0icomplex(8):: val ! 4.1023…. + 3.020i
Examples: type(mfArray) :: a real(8), dimension(10,10) :: b, c a = (/1.0, 2.0, 3.0, 4.0, 5.0/) a = “This is a string” a = (2.0, 1.0) a = (/1.0, 2.0, 3.0/).vc.(/4.0, 5.0, 6.0/) ! vertical concatenation a = b > c ! logical
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 12: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/12.jpg)
mfArray Constructors
Constructorscontained in mod_elmat, mod_ops. modulesuseful for initializing mfArrays
Example: type(mfArray) :: a, b
a = mfZeros(10, 10) ! 10 by 10 matrix of zeros a = mfOnes(10, 10, 10) ! 10 by 10 by 10 3D array of ones a = mfRand(2, 2, 2, 2) ! Random 2 by 2 by 2 by 2 4–D array a = mfMagic(3, 3) ! 3-by-3 magic matrix a = mfEye(2, 2) ! 2-by-2 identity matrix a = mfReshape((/1, 2, 3, 4/), (/2, 2/)) ! Similar to Fortran reshape function a = mfColon(2.0, 0.5, 10.0) ! equivalent to subscript
triplet(2.0:10.0:0.5) a = mfLinspace(0.0, 2.0, 100) ! vector with100 eq. incr. betw 0.0 and 2.0
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 13: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/13.jpg)
Array Element Ordering
Organization in memory:Elements of a mfArray are arranged column major-wise as specified by Fortran 90 standard.
1st ElementC(1,1)
5th ElementC(5,1)
6th ElementC(1,2)
Last - 15th Element C(5,3)
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 14: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/14.jpg)
Element Subscript
Array elements are specified through their subscripts which contain positions at each dimension.
General syntax : [posdim1, posdim2, posdim3,…, posdim7]
Examplea scalar has subscript (1,1)the fifth element of a row vector is (1,5)the second element of a column vector is (2,1)the sixth element of a 3-by-3 matrix is (3,2)an element on a 3D array is (posdim1, posdim2, posdim3)
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 15: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/15.jpg)
mfArray Inquiry Procedures
l = IsEmpty(b) returns logical true if mfArray b is empty
l = mfAll(b) returns true if all elements are nonzeros
l = mfAny(b) returns true if any element is nonzero
a =mfSize(b) returns total number of elements or extent of a dimension
l = mfIsEqual(a, b, c, d...) returns true same shape and values.
l = mfIsLogical(a) returns true if mfArray is logical
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 16: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/16.jpg)
mfDisplay, mfGDisplay
You can display the elements of a mfArray by using the mfDisplay or msGDisplay procedures.
call msDisplay(a, ‘a’)
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
call msGDisplay(a, ‘a’)call msViewPause
![Page 17: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/17.jpg)
mfArray and Fortran Data Type
type(mfArray) :: x
real(8) :: Dx
real(8), pointer :: Px(:,:)
Assignx = mf(Dx) ! Assign Dx value to x
Pointercall msPointer(x,Px) ! Assign real(8) pointer to a
target x
Equivalentx = mfEquiv(Dx) ! Sharing memory storage between Dx and x
![Page 18: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/18.jpg)
mfArray and C++ Data Type
mfArray x;
double Dx[6] ={1,2,3,4,5,6};
double Dy;
Assignx = mfArray(Dx, 2, 3); ! Assign Dx value to x
or x = mf(Dx, 2, 3);
PointerDy = x.ToDouble(); ! Converts an mfArray to a double
![Page 19: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/19.jpg)
mfLoad, msSave
You can export the data in a mfArray to a text or binary file. Syntax: call msSave(<filename>, <mfArray>)
Example call msSave( “a.txt”, a)
mfLoad procedure loads data into a mfArray from a text file.Syntax: b = mfLoad(<filename>)
Example a = mfLoad(“a.txt”)
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 20: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/20.jpg)
Notice
Subroutine Dummy Arguments
Function Return Array
IF Statement
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 21: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/21.jpg)
Subroutine Dummy Arguments
Use the msInitArgs and msFreeArgs procedures when mfArrays act as dummy arguments in your subroutine
General Format:
SUBROUTINE < procname >[ (<mfArray dummy args >) ]
call msInitArgs(<mfArray dummy args>)
. ..
< executable stmts >
call msFreeArgs(<mfArray dummy args>)
END [ SUBROUTINE [< procname > ] ]
Example Subroutine foo(a, b) ! a and b are mfArrays type(mfArray):: a, b call msInitArgs(a, b) ...
call msFreeArgs(a, b) end Subroutine foo(a, b)
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 22: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/22.jpg)
Functions
Use procedure mfReturnArray when mfArray acts as function output arguments.
General Format:
[< prex >] FUNCTION < procname >( [< mfArray type dummyargs >])
. ..
< executable stmts, assignment of result >
call msReturnArray(< mfArray type dummyargs >)
END [ FUNCTION [ < procname > ] ]
Example
Function foo(i) result(a)
type(mfArray):: a
... call msReturnArray(a)
end function foo
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 23: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/23.jpg)
MATFOR in IF Statement
The basic syntax is,
if (mfAll(< logical-expression >)) < exec-stmt >
mfAll returns a Fortran logical data type.
Example, if (mfAll(a>3)) ……
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 24: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/24.jpg)
mfArray operator
![Page 25: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/25.jpg)
Matrix Operations
You can perform matrix operations with mfArray.
mfMul(x,y) - returns the linear algebraic product of mfArrays a and b, where x is a m-by-p matrix and y is a p-by-n matrix. The product returns a m-by-n matrix.
mfRDiv(x,y) – solves simultaneous equation denoted by x/y. Result is ~ x* inv(y)
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 26: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/26.jpg)
Function Calling Convention
MATFOR procedures are prefixed with either “mf” or “ms”.
Procedures with prefix “mf” are function procedures.
Example
a = mfIsEmpty(b)
y = mfSin(x)
y = mfLoad(“filename.txt”)
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 27: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/27.jpg)
Function Calling Convention
Procedures with prefix “ms” are subroutine procedures.
Example call msLU(mfOut(l, u), a) call msMeshgrid(mfOut(a, b), m, n) call msViewPause()
The function mfOut() specifies output arguments in the subroutine call format. You must specify mfOut whenever you use the subroutine call format.
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 28: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/28.jpg)
MATFOR Operators
Operators Description Precedence
.h. mfArray complex transpose Highest
.t. mfArray transpose
** mfArray power.
* mfArray multiplication
/ mfArray right division
\ mfArray left division
+ mfArray addition or unary plus.
- mfArray subtraction or unary minus.
>= mfArray greater than or equal to comparison.
> mfArray greater than comparison.
<= mfArray less than or equal to comparison.
< mfArray less than comparison.
/= mfArray inequality comparision.
== mfArray equality comparision.
.hc. Horizontal concatenation
.vc. Vertical concatenation
mfMul mfArray matrix multiplication
mfLDiv mfArray matrix left divide
mrRDiv mfArray matrix right divide Lowest
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 29: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/29.jpg)
Precedence Example
The following expression,x = .t.a**2
is equivalent tox = ((.t.a)**2)
as .t. has the highest precedence followed by **.
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 30: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/30.jpg)
MATFOR Parameters
Parameter Description
MF_EPS Floating-point precision = epsilon(1d0)
MF_PI 3.1415926535897
MF_REALMAX Largest floating-point number =huge(1d0)
MF_REALMIN Smallest floating-point number=tiny(1d0)
MF_I Imaginary unit (0d0, 1d0)
MF_INF Infinity
MF_NINF Negative infinity
MF_NAN Not-A-Number
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 31: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/31.jpg)
exam1 for Fortran
exam2 for Fortran without fml
exam3 for C++
exam4 for C++ without cml
exam5 for Fortran without mfFiqure
exam6 for Fortran with Subplot
Quick Start
![Page 32: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/32.jpg)
Program plot
use fgluse fml
implicit none
integer, parameter :: nx = 30, ny = 25type(mfArray) :: lx, ly, x, y, ztype(mfArray) :: h
lx = mfLinspace(-3, 3, nx)ly = mfLinspace(-3, 3, ny)call msMeshgrid( mfOut(x, y), lx, ly )
z = mfSin(x) * mfCos(y) / ( x*(x-0.5d0) + (y+0.5d0)*y + 1) ! ******************************************************************! Figure equation! ******************************************************************call msFigure('equation')
! ******************************************************************! surf! ******************************************************************call msTitle('MATFOR Course Example')h = mfSurf(x, y, z) call msViewPause
end Program plot
exam1
![Page 33: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/33.jpg)
Program plot
use fgl
implicit none
integer, parameter :: nx = 30, ny = 25real(8) :: x, y, z(ny, nx)integer :: i, j
do i=1,nydo j=1,nx
x = -3 + j * 6d0 / nxy = -3 + i * 6d0 / nyz(i, j) = sin(x) * cos(y) / ( x*(x-0.5d0) + (y+0.5d0)*y + 1)
end doend do
! ******************************************************************! Figure equation! ******************************************************************call msFigure('equation')
! ******************************************************************! surf! ******************************************************************call msTitle('MATFOR Course Example Using Fortran Array')call msSurf(mf(z)) call msViewPause
end Program plot
exam2
![Page 34: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/34.jpg)
#include <fgl.h>#include <cml.h>
void main(){
const int nx = 30, ny = 25;mfArray lx, ly, x, y, z;mfArray h;
lx = mfLinspace(-3, 3, nx);ly = mfLinspace(-3, 3, ny);mfMeshgrid( mfOut(x, y), lx, ly );
z = mfSin(x) * mfCos(y) / ( x*(x-0.5) + (y+0.5)*y + 1);
// ******************************************************************// Figure equation// ******************************************************************mfFigure("equation");
// ******************************************************************// surf// ******************************************************************mfTitle("MATFOR in C++ Example");h = mfSurf(x, y, z); mfViewPause();
}
exam3
![Page 35: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/35.jpg)
#include <math.h>#include <fgl.h>
void main(){
const int nx = 30, ny = 25;double x, y, z[nx][ny];int i, j;
for (i=0; i<nx; ++i){
for (j=0; j<ny; ++j){
x = -3 + i * 6.0 / nx;y = -3 + j * 6.0 / ny;z[i][j] = sin(x) * cos(y) / ( x*(x-0.5) + (y+0.5)*y
+ 1);}
}
// ******************************************************************// Figure equation// ******************************************************************mfFigure("equation");
// ******************************************************************// surf// ******************************************************************mfTitle("MATFOR Course Example Using C++ Array");mfSurf( mfArray( (double*) z, ny, nx ) ); mfViewPause();
}
exam4
![Page 36: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/36.jpg)
Program plot
use fgluse fml
implicit none
integer, parameter :: nx = 30, ny = 25type(mfArray) :: lx, ly, x, y, ztype(mfArray) :: h
lx = mfLinspace(-3, 3, nx)ly = mfLinspace(-3, 3, ny)call msMeshgrid( mfOut(x, y), lx, ly )
z = mfSin(x) * mfCos(y) / ( x*(x-0.5d0) + (y+0.5d0)*y + 1) call msGDisplay(z, 'z') call msViewPause
end Program plot
exam5
![Page 37: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/37.jpg)
Program plot
use fgluse fml
implicit none
integer, parameter :: nx = 30, ny = 25type(mfArray) :: lx, ly, x, y, z
lx = mfLinspace(-3, 3, nx)ly = mfLinspace(-3, 3, ny)call msMeshgrid( mfOut(x, y), lx, ly )
z = mfSin(x) * mfCos(y) / ( x*(x-0.5d0) + (y+0.5d0)*y + 1) ! ******************************************************************! Figure equation! ******************************************************************call msFigure('surface')
! ******************************************************************! surf! ******************************************************************call msTitle('MATFOR Course Example')call msSurf(x, y, z)
exam6
! ******************************************************************! Figure subplot! ******************************************************************call msFigure('subplot')
! ******************************************************************! subplot 1! ******************************************************************call msSubplot(1,2,1)call msTitle('Subplot 1')call msSurf(x, y, z)
! ******************************************************************! subplot 2! ******************************************************************call msSubplot(1,2,2)call msTitle('Subplot 2')call msSurf(x, y, z) call msViewPause
end Program plot
![Page 38: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/38.jpg)
Numerical library
![Page 39: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/39.jpg)
Linear Algebra
Matfor supports many matrix operations commonly used in Linear algebra, including matrix arithmetic, linear equations, eigenvalues, singular values and matrix factorizations.
Matrix analysis:n = mfNorm(x) ! Computes vector matrix 2-normd = mfDet(x) ! Computes matrix determinants = mfTrace ! Computes diagonal sum of elements
Linear equations:y = mfInv(x) ! Computes matrix inversec = mfCond(x) ! Condition no. for inverser = mfChol(x) ! Cholesky factorizationr = mfQr(x) ! Orthogonal-triangular decomposition
Eigenvalues and singular values:e = mfEig(a) ! Computes eigen values and eigen vectorss = mfSvd(a) ! Singular value decompositiont = mfSchur(a) ! Schur decomposition
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 40: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/40.jpg)
example
program eig
use fmluse fgl
implicit none
type(mfArray) :: x, eig_value, eig_vector
x = mfRand(5)
eig_value = mfEig(x)
call msGDisplay(x,'x',eig_value,'eigvalue')call msViewPause()
call msEig(mfOut(eig_vector,eig_value),x)
call msSurf(eig_vector)call msGDisplay(eig_value,'eigvalue',eig_vector,'eigvector')call msViewPause()
end program
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 41: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/41.jpg)
export, print,
show all, auto-rotate,
roation, zoom, pcik, home,
material, axis, colorbar,background,
data viewer,
translation,
xlabel, ylabel, zlabel, title,
continue.
Graphic Viewer
![Page 42: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/42.jpg)
Data Viewer
Data sheet (col width, precision),
snapshot ( red rectangle),
analysis(histogram, min, max, avg, std),
filter ( x <avg+3*std ),
export text -> excel,
goto
![Page 43: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/43.jpg)
Graphic LibraryGraphic Viewer
Figure
Subplot
Axis
Draw
![Page 44: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/44.jpg)
Graphic Library
Graphic Viewer Programming API
Graphic Object
Animation
DrawMaterial
Texture
![Page 45: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/45.jpg)
Graphic Viewer Programming API figure, subplot, background, title, xlabel, ylabel, zlabel, axis(on/off), axis(range),axisgrid, axiswall, view, camzoom, colormap, colorbar, colormaprange
see example graphic viewer api.dsw
![Page 46: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/46.jpg)
Graphic Object
plot, surf, pcolor, contour(3), isosurface,
trisurface, quiver, (fast)molecule,
cube/cylinder
see example draw.dsw
![Page 47: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/47.jpg)
2-D Elementary Plots
Procedure mfPlot plots two-dimensional graphs. It has the following formats:
call msPlot(x, y)
call msPlot(y)
call msPlot(x, y, ‘linspec’)
call msPlot(x, y, ‘linspec’, x1, y1, ‘linspec1’, ......)
Example:
use fgl
use fml
implicit none
type(mfArray) :: x, y
x = mfLinspace(-MF_PI, MF_PI, 100)
y = mfCos(x)
call mfPlot(x, y, ‘ro-’)
call mfViewPause()
![Page 48: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/48.jpg)
linespec
Character Line color Character Marker
TypeCharacter Line Type
y yellow . point - solid
m magenta o circle : dotted
c cyan x x-mark -. dashdot
r red + plus -- dashed
g green * star
b blue s square
w white d diamond
k black v triangle
down
^ triangle up
< triangle left
> triangle
right
![Page 49: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/49.jpg)
Axis and Annotations
mfAxis – controls the axes object.call msAxis(‘off’)call msAxis( ‘on’)call msAxis((/xmin, xmax, ymin, ymax/))call msAxis((/ximn, xmax, ymin, ymax, zmin, zmax/))call msAxis(mf('xaxis_ticks'), mf((/-4.0d0, 0.0d0, 4.0d0/)))
mfTitle – titles the Graph.call msTitle(‘Title of Graph’)
mfXLabel, mfYLabel, mfZLabel – labels the axes.call msXLabel(‘x-axis label’)call msYLabel(‘y-axis label’)call msZLabel(‘z-axis label’)
![Page 50: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/50.jpg)
3D-Plots
mfPlot3 – plots 3-D line graphcall msPlot3(x, y, z)
Example:use fgluse mod_elmatimplicit nonetype(mfArray) :: x, y, z, indxi, indxj, hcall msMeshgrid(mfOut(x, y), mfLinspace(-3,7,30), mfLinspace(-3,
8,30))call msMeshgrid(mfOut(indxi, indxj), [1:30], [1:30])z = 3d0*mfSin((indxi+1)/4d0)*mfCos((indxj+1)/4d0)& +2d0*mfSin((indxi+indxj)/4d0)call msPlot3(x, y, z)call msViewPause()
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 51: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/51.jpg)
Surface plot
mfxSurf – plots a 3-D graph composed of surfacescall msSurf(z)
call msSurf(x, y, z)
Example: (cont’d from previous slide)
call msSurf(x, y, z)
call msShading(‘facet’)
call msViewPause()
msShading – sets the shading type of the surface plots
options available includes ‘mesh’, ‘flat’, ‘interp’, ‘facet’.
by default, mfSurf plots ‘facet’ while mfMesh plots ‘mesh’.
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 52: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/52.jpg)
Surface plot
mfColorbar – turns the colorbar on or offcall msColorbar(‘on’)call msColorbar(‘off’)
mfView – specifies the elevation and azimuth view angles
call msView(2) ! 2-D viewcall msView(3) ! default 3-D view, az=-37.5. el=30call msView(az, el)
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 53: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/53.jpg)
Contours
mfContour – plots constant value lines in 2-D view
call msContour(z)call msContour(x, y, z)
mfContour3– plots constant value lines in 3-D view
call msContour3(z) call msContour3(x, y, z)
Example: (cont’d from previous slide) call msContour(x, y, z) call msViewPause() call msContour3(x, y, z) call msViewPause()
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 54: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/54.jpg)
Steps to Animation
Step 1: Add use fgl under your program name (or module name, procedure name, function name)
use fgl
Step 2: Construct the mfArrays for plotting.
type(mfArray) :: x, y
x = [1:10]
y = mfCos(x)
Step 3: Select a Graphics Viewer for plotting (optional)call msFigure(1)
Step 4: Create a Graph and get its handleh = mfPlot(x, y)
Step 5: Set up iteration loop for the target variable Loop
Step 6: Use mfGSet to update the target variable.call msGset(h, ‘ydata’, y)
Step 7: Use mfDrawnow to update Graphics Viewer
Step 8: Use mfViewPause to pause program
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 55: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/55.jpg)
Animation
Example (cont’d from previous example)! Get handle of mfPlot3 graphh = mfPlot3(x, y, z)
! Do loop to calculate zdo i = 1, 100 z = 3d0*mfSin((indxi+i+1)/4d0)*mfCos((indxj+1-i)/4d0)& +2d0*mfSin((indxi+indxj+i)/4d0)
! Update z call msGSet( h, ‘zdata’, z) ! Update Graphics Viewer call msDrawNow()end docall msViewPause()
What is mfArray
mfArray operator
Numerical library
Graphic library
Example
Q & A
![Page 56: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/56.jpg)
AnimationProgram animation
use fgluse fml
implicit none
integer, parameter :: nx = 30, ny = 25type(mfArray) :: lx, ly, x, y, ztype(mfArray) :: hinteger :: i
lx = mfLinspace(-3, 3, nx)ly = mfLinspace(-3, 3, ny)call msMeshgrid( mfOut(x, y), lx, ly )
call msMeshgrid( mfOut(x, y), lx, ly )
z = mfSin(x) * mfCos(y) / ( x*(x-0.5d0) + (y+0.5d0)*y + 1) h = mfSurf(x, y, z)call msAxis(mf((/-3,3,-3,3,-1,1/)))
do i = 1, 100 z = mfSin(x+i*0.1d0) * mfCos(y+i*0.1d0) / ( x*(x-0.5d0) + (y+0.5d0)*y + 1)
! Update z call msGSet( h,'zdata', z)
! Update Graphics Viewer call msDrawNow()end do
call msViewPauseend Program animation
![Page 57: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/57.jpg)
Material Setting
![Page 58: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/58.jpg)
DrawMaterial
mfDrawMaterial(handle, target, property, value)
target as "surf", "edge" or "both".
property and value can be:
![Page 59: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/59.jpg)
Property Meaning
“trans” Transparency reflectance. The corresponding argument value can be an integer or an mfArray containing an integer that ranges from 0 to 100.
“ambient” Ambient reflectance. The corresponding argument value can be an integer or an mfArray containing an integer that ranges from 0 to 100.
“diffuse” Diffuse reflectance. The corresponding argument value can be an integer or an mfArray containing an integer that ranges from 0 to 100.
“specular” Specular reflectance. The corresponding argument value can be an integer or an mfArray containing an integer that ranges from 0 to 100.
“color” Color component. The corresponding argument value can be an mfArray containing the rgb vector [r, g, b] or an mfArray containing the string that is specified as “on” or “off”.
![Page 60: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/60.jpg)
Property Meaning
“colormap” Turn the colormap on or off. The corresponding argument value can be an mfArray containing the string that is specified as “on” or “off”.
“visible” Turn the surface or edge on or off. The corresponding argument value can be an mfArray containing the string that is specified as “on” or “off”.
“smooth” Interpolate to Gouraud shading. The corresponding argument value can be an mfArray containing the string that is specified as “on” or “off”.
“line_width” Line width of edge. The corresponding argument value can be an integer or an mfArray containing an integer.
“line_style” Line style of edge. The corresponding argument value can be an mfArray containing a string that is specified as "solid", "dashed", "dotted" or "dashdot".
![Page 61: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/61.jpg)
program DrawMaterialuse fgluse fmlimplicit nonetype (mfArray) :: a, x, y, z, ha = mfLinspace(-3, 3, 30)call msMeshGrid( mfOut(x, y), a)z = mfSin(x) * mfCos(y) / ( x*(x-0.5d0) + (y+0.5d0)*y + 1) h = mfSurf(x, y, z)call msDrawMaterial(h, mf('surf'), mf('visible'), mf('on'), & mf('smooth'), mf('on'), & mf('colormap'), mf('on'), &
mf('ambient'), mf(0), & mf('diffuse'), mf(75), & mf('specular'), mf(25))
call msDrawMaterial(h, mf('edge'), mf('color'), mf((/1,0,0/)), & mf('smooth'), mf('on'), & mf('colormap'), mf('off'), & mf('ambient'), mf(0), & mf('diffuse'), mf(0), & mf('diffuse'), mf(0), & mf('specular'), mf(0), & mf('trans'), mf(90))
call msViewPause()call msFreeArgs(a, x, y, z, h)end program DrawMaterial
![Page 62: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/62.jpg)
Texture
call msDrawTexture(handle, property, value)
Arguments property and value can be:
Property Meaning
"enable" Enabling or disabling the texture-mapping. The corresponding argument value can be “on” or “off”.
"map" Specifying the texture file. The corresponding argument value specifies the name of a bitmap file(e.g. texture.bmp).
"coord_s" Texture’s s-coordinate. The corresponding argument value is a vector of values ranging from 0 to 1 which specifies the way of mapping.
"coord_t" Texture’s t-coordinate. The corresponding argument value is a vector of values ranging from 0 to 1 which specifies the way of mapping.
![Page 63: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/63.jpg)
program DrawTexture
use fgluse fmlimplicit none
type (mfArray) :: a, x, y, z, h
a = mfLinspace(-3, 3, 30)call msMeshGrid( mfOut(x, y), a)z = mfSin(x) * mfCos(y) / ( x*(x-0.5d0) + (y+0.5d0)*y + 1)
h = mfSurf(x, y, z)call msDrawTexture(h, 'map', 'ancad.bmp')call msDrawMaterial(h, mf('surf'), mf('smooth'), mf('on'),&
mf('colormap'), mf('on'), & mf('ambient'), mf(0), & mf('diffuse'), mf(15), & mf('specular'), mf(85))
call msDrawMaterial(h, 'edge', 'visible', 'off')call msViewPause()
call msFreeArgs(a, x, y, z, h)
end program DrawTexture
![Page 64: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/64.jpg)
MATFOR 3 in Fortran Register
程式集 -> MATFOR3 -> Utilities -> Register MATFOR in Fortran 3.0
![Page 65: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/65.jpg)
MATFOR 3 CA
程式集 -> MATFOR3 -> Utilities -> MATFOR CA
將 MATFOR 的 dll 檔放在經過 CA 後的執行檔相同目錄下,
在沒安裝 MATFOR 的電腦上即可執行含 MATFOR 含式的執行檔。
![Page 66: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/66.jpg)
Q&A
Send Questions, Requirements, Etc. to…http://www.ancad.com
Randy WuApplication [email protected](02)8923-5411~13
![Page 67: Programming with MATFOR 3 吳衍憲 Randy Wu Application Engineer (02)8923-5411~13 randy@ancad.com](https://reader033.vdocuments.net/reader033/viewer/2022061614/56649e375503460f94b26fd6/html5/thumbnails/67.jpg)
謝謝您的參與!