. About Matcad MATHCAD'S PROGRAM FUNCTION and APPLICATION IN TEACHING OF MATH DE TING WU Depart of Mat Moreouse College Atlanta, GA.33, USA dtwu@moreouse.edu. Introducton Matcad s one of popular computer algebra system (mat software) n te world. Lke oter CAS's, t as te capabltes to perform algebrac operatons, calculus operatons and draw grap of or 3 dmensons. We can use t to get numercal, symbolc and grapc soluton of mat problem. Besdes above common capabltes, t as some feature: ts words processor functon s better tan oter CAS. Ts feature makes t look lke a scentfcal words processor and t easy to create a wokseet. Followng current trend to add program functon to mat software, t added program functon to tself, started n Matcad V7. Ts mprovement makes ts functon more complete and more powerful.. Role of program functon n teacng of Mat. Wtout doubt, mat softwares and tecnology are elpful ade n teacng of Mat. Tey are effectng te teacng of Mat profoundly and t can be expected te emergng newer tecnologes wll penetrate and reconfgure te teacng of Mat. Te program functon s a new functon of mat software. It s natural we want to know weter or not t s useful n teacng of Mat? I tnk: altoug for most problems we meet n teacng of Mat t s enoug to use computaton ablty, n certan cases te program functon becomes necessary and very elpful. For example, for Numercal Analyss te program functon s very useful but for Abstract Algebra t s less necessary. Anoter example s Dfferental Equatons, wen teacng approxmate metod for a soluton of a dfferental equaton te program functon s necassary and teacng exstence and unquess of te soluton of a dfferental equaton t s not necessary. Moreover, as te power of program functon s ncreasng te more applcatons wll be found..3 About ts presentaton Ts presentaton s to ntroduce te program functon of Matcad and llustrate some of applcaton n teacng of Mat wc s based on my teacng experence n past years.
. Program functon of Matcad In ts part te program operators of Matcad and te structure of Matcad program are ntroduced.. Program operators of Matcad Matcad program s created by usng ts program operators. Matcad as operators wc are accassable from Program toolbar. Now, let's take a look of tese operators.."add lne": operator to ntate a program or add a lne to a program. Wen clck t on te programmng toolbar a vertcal bar and placeolds wll be produced.. " ": local assgn operator wc defne left older by rgt older of arrow. 3. " f ": condtonal operator wc can be used wenever you want a program statement to be executed only upon te occurrence of some condton.." oterwse": condtonal operator wc can be used togeter wt "f" operator wen you want a program to execute a statement wen te condton of "f" operator s false. 5." for " : loopng operator wc can be used wen you know ow many tmes you want a program statement to be executed repeatedly.." wle ": loopng operator wc can be used wen you want to stop executon of a statement upon te occurrence of a condton but don't know exactly wen te condton wll occur. 7." break ": Control operator wc can be used wen you want to break out of a loop. upon te occurrence of some condton and wc moves executon to next starement outsde te loop. 8. " contnue ": Control operator wc can be used wen you want to alt current teraton of a loop upon te occurrence of a condton and force program to contnue next teraon of a loop. 9." return ": Control operator wc can be used anywere n a program wen you want to nterrupt a program and to return a value dfferent from te value of last expresson of a program.." on error ": Operator for error control wc can be used to return an alternatve value wen an error appened n an expresson.
. Structure of Matcad program A program s a precse sequence of nstructons desgned to accompls a specfc task. Matcad program s a sequence of statements created by usng program operators, too. But, t as specal form and structure. Now, we use an example to llustrate. Example of Matcad program f( x, y) := u x + y v sn( u) + e u w + u v w Left s a Matcad program wc defnes a functon n varable. Ts program conssts of parts. Left part s name or varable name wc represent te output of last statement n te program; Rgt part s ncluded n a vertcal bar wc s te body of te program comprsed of program operators. Bot parts are connected by te defnton sgn " := ". Ts means Left part s defned by rgt part or te program assgns te result to te name on te left. In fact, te program just s a compound expresson wc s represented by name on te left. Te form and structure of Matcad program make t easy to recognze and separate from oter part of workseet. Te program operators are smple so tat wrtng a program s smple. Ts s very sutable for teacng purpose. Ts form and structure s good for revsng of program too. Also, ts form and structure make t convenent to nteract wt oter parts of a workseet. Altoug Matcad program s comprsed of ts program operators, a lot of ts bult-n functons can be used n te program too. For example, augment, sgn, random varable and so on. Ts makes ts program more concse and powerful. Te output of Matcad program maybe s a number, a vector, a matrx and a functon, ts makes ts applcaton wde and flexble. However, te program functon of Matcad s as lmted as oter tecnologes. For example, Not all ts bult-n functons can be used n Matcad program and some of tem can not be used completely and symbolc operatons don't work wtn a program. Anyway, Program functon of Matcad s a useful tool n teacng of Mat.
3. Applcaton n teacng of Dfferental Equatons Matcad's program functon can be appled to te teacng of Dfferental Equatons. Altoug Matcad as several bult-n functons(or routnes) for solvng of dfferental equatons, suc as Odesolve, rkfxed, rkadapt, etc, tere're cases we need ts program functon. For example, wen teacng approxmate metods solvng dfferental equatons and tey are dfferent from tose wc are bass of above bult-n functons, Matcad program functon becomes necessary and elpful. Esspecally, n comparson of dfferent approxmate metods. In ts part we'll llustrate ts applcaton by exampltes. 3. Appcaton to one dfferental equaton In ts secton we 'll use Matcad's program functon to wrte programs to perform Euler metod and Improved Euler metod for a frst order dfferental equaton and compare ter results wt te exact soluton and te results of bult-n functon troug an example. Let's consder followng example. Gven: y'=+ y y + and y()=, x n [,]; Fnd: ts approxmate soluton over gven x x nterval by Euler metod and Improved Euler metod wt step sze =. and errors. To make programs of Euler and Improved Euler metod Program of Euler metod Program of Improved Euler Metod Eu( f, a, b, c, ) := x a y b c a n for.. n P P x x + + y y + f x, y + augment( x, y) IEu( f, a, b, c, ) := x a y b c a n for.. n P P x x + + y y + f x, y + y y + + f x, y augment( x, y) ( + f( x, y + + ) ) Note: n above programs Left sde s te output of te program wc s a matrx of x- value and approxmate soluton values. Rgt sde s te program wc uses te nput: 'f' functon of ODE, 'a' ntal x value; 'b' ntal y value; 'c' end pont of te nterval; '' step sze and perform approxmate metod to produce approxmate soluton. Now, let's us tese programs to get approxmate solutons of above example.
In above example, Let y y f( x, y) := + + a := b := c := :=. x x A := Eu( f, a, b, c, ) B := IEu( f, a, b, c, ) ten, Approxmate soluton produced by Euler matod: A T 3 5 7 8 9 =...3..5..7.8.9..99.335..3.73.9335.85.393 Approxmate soluton produced by Improved Euler metod: B T 3 5 7 8 9 =...3..5..7.8.9.5.8.383.885..8.99.955.5 It's not ard to fnd ts exact soluton: g( x) := x tan( ln( x) ) :=.. x := +. Also, fnd ts soluton by bult-n functon Odesolve' Gven y' ( x) + y( x) x y( x) + y x y := Odesolve ( x, ) y( x ) 3.5..39.897 = g x = 5.39 3 5.5..39.897.39.88.88 7.9975 7.9975 8.99 8.99 9. 9..3.3 Now, we grap tese solutons n a pcture.
( A ) ( B ) g( x ) y( x ).5.5....8 x Next, let's analyze ter error. we defne error of Euler metod and Improved Euler Metod as ErEu and ErIEu. ( A ) ErEu := g x ErIEu := g x B ErEu T = 3 5 5.598-3.3.87.73.37 ErIEu T = 3 5. -.7-8.7 -.8-3.73-3 ErEu. ErIEu.5....8 x
3. Applcaton to system of dfferental equatons In ts secton we'll wrte a program to mplement Improved Euler metod to fnd te approxmate solutons of a system of 3 dfferental equatons and analyze te error. Frst, wrte te program IEu( f, f, f3, a, b, c, d, l, ) := t a u b u c u3 d l a n for.. n P P P P t t + + (,, u, u3 ) (, ) u u + f t, u, u, u3 + u u + f t u + u3 u3 + f3 t, u, u u3 + ( + f( t, u, u, u3 + + + + ) ) u u + + f t, u u,, u3 ( + f( t, u, u, u3 + + + + ) ) u u + + f t, u u,, u3 ( + f3( t, u, u, u3 + + + + ) ) u3 u3 + + f3 t, u u,, u3 augment( t, u) augment( P, u) augment( P, u3) Now, we use ts program to fnd approxmate solutons of followng example. Gven: u'= u u()= u'= -u- e t + u()= t n [,] u3'=-u- e t + u3()= Fnd: ts approxmate solutons by Improved Euler metod wt step sze =. In ts example f( t, u, u, u3) := u f( t, u, u, u3) := u e t + f3( t, u, u, u3) := u a := b := c := d := l := :=. e t +
Let A := IEu( f, f, f3, a, b, c, d, l, ) 3 ten ts approxmate soluton s sown n te rgt matrx. Te st column s t-value ; Te nd column s u-value; Te 3rd column s u-value; Te t column s u3-value. A = 3 5..99 -.5.897..9579 -..785.3.98 -.98.583..89 -.97.595.5.793 -.539.3953..589 -.557.57 7.7.393 -.8983.3 8.8.893 -.5 -.58 9.9 -.5 -.8 -.78 -.333-3.78 -.38 Its exact solutons are : g( t) := cos( t) + sn( t) e t + g( t) := sn( t) + cos ( t) e t g3( t) := sn( t) + cos ( t) :=.. t :=. g( t ) 3.887 = g t 5.783 7 8 9.9897.9573.9.579.3953.885 -.57 -.335 3 7 8 9 -. -. -.9 -.5 -.893 -. -.3-3.95 -.9 = g3 t = 5 -.5 3 5 7 8 9.895.78.598.53.398.7. -. -.7 -.3 Next, we make grapes. Ist one s grap of 3 approxmate solutons; nd one s te grap of u and g; 3rd one s te grap of u and g; t s grap of u3 and g3.
A A A 3.5 ( A ) g( t ).5.5.5 ( A ) t.5 ( A ) g( t ) ( A 3 ) g3( t ).5.5.5 t t Now, let's analyze te error. We defne error n u, u, u3 as Eru, Eru, Eru3. g( t ) g( t ) Eru A := Eru A := Eru3 A 3 := g3( t ) Eru T = 3 5 3.333 -.33-8.375-9.855 -.3-3 Eru T = 3 5 5.9 -. -3.79-3.573-3 3.399-3 Eru3 T = 3 5.99-9.389 -.53-3.375-3.89-3
Te grap of tese errors as follows:.8 Eru. Eru Eru3......8 t
. Applcaton n teacng of Numercal Analyss Numercal Analyss s anoter area n wc Matcad's program functon can dsplay ts full potental. Snce Numercal Analyss often needs massve, repeated and tedous computaton te program functon can best meet ts requrement. In ts part we just llustrate ts applcaton n fndng approxmate soluton of non-lnear equatons and Newton's nterpolaton polynomal.. Applcaton of fndng approxmate soluton of non-lnear equatons In ts secton we'll use program functon of Matcad to wrte a program to perform Secant metod to fnd approxmate soluton of non-lnear equatons. And, we'll compare te result wt bult-n functon's result. Program for Secant metod. ApS( f, a, b, r) := p a p b wle p p p p p p p p p f( p) r p f( p) f( p) f( p) Note: Input: f(x)=- gven equaton a,b-endponts of [a,b] tat bracket te soluton r-desred accuracy Output: Approxmate soluton satfyng accuracy Now, let's see an example: Fnd approxmate soluton of cos(x)-x= wt accuracy 5. f( x) := cos( x) x f = f =.59979 a := b := r := 5 Use grap to locate soluton n [,] Te desred approxmate soluton: x:= ApS( f, a, b, r) x =.739853 f( x) x Let's compare wtresult from bult-n functon. r := root( f( x), x,, ) r =.739853 Let's ceck te error er := x r er =.5937 3
. Applcaton n fndng Newton nterpolaton polynomal In ts secton we'll use te program functon to make a program to produce te coeffents of Newton nterpolaton polynomal ten use symbolc operaton to form Newton nterpolaton polynomal. Also, te grap of Newton polynomal s provded. We llustrate by below example. Example.Gven: f()=.75977, f(.3)=.8, f(.)=.55, f(.9)=.888, f(.)=.33. Construct nterpolatng polynomal of degree by Newton's nterpolatory dvded dfference formula and use t to approxmate f(). Sol'n: Frst, enter te data: a := a :=.3 a :=. a :=.9 a :=. 3 b :=.75977 b :=.8 b :=.55 b :=.888 b :=.33 3 Second, use followng program to fgure out dvded-dfferences. In followng program, use a for-loop to enter above set of data, and ten use double for-loop to fgure out te dvded-dfferences. Te output of te program s a matrx and te elments on te dagonal are te dvded-dfferences needed n Newton's formula. f := for for f.. x a for f b,.. j.. f f, j, j f, j x x j f =.75977.8.55.888.33.83757.589.578.575.873389.9333.8833.5878.885.8588 3 Ten, use Newton's nterpolatory dvded-dfference formula to construct polynomal. p( t) := f +, = f, ( t a k ) k = p( t) smplfy.977735+ 7.3393 - t.337t + 5.598 - t 3 +.85-3 t float,
Ten, fnd te approxmate value of f() s p =.38753 Fnally, Plot te data ponts and Newton's nterpolaton polynomal n a grap below: :=.. t :=,.... Grap of data ponts and Newton's poly. b p( t).5.5.5.5 a, t 5. Reference [] R.L.Burden & J.D.Fares:"Numercal Analyss" 7t edton, Brooks/Cole,. [] L.Fausett: "Numercal Metods Usng Matcad", Prentce Hall,. [3] R.K.Nagle, E.B.Staff & A.D.Snde: "Fundamentals of Dfferental Equatons" t edton, Addton Wesley, [} D.T.Wu: "Usng Matcad n Teacng Dfferental Equatons", Electronc Proceedngs of ICTMT, 999. Web ste: www.tec.plym.ac.uk/mats/ctmhome/ctmt.tml [5] D.T.Wu: "Teacng Numercal Analyss wt Matcad", "Internatonal Journal of Computer Algebra n Matematcs Educaton" Vol No., 3.