Roo idig The solio of oliea eqaios ad sysems Vageli Cosias, UNM, all The Newo-Raphso ieaio fo locaig zeos f ( )/ f ( ) ' f '( ) f ( )
Eample: fidig he sqae oo f f ( ) '( ) a a a Deails: iiial ieae ms be close o solio fo mehod o delie is pomise of qadaic coegece (he mbe of coec bis doblig wih eey sep) fcio sq(a) if A < beak;ed if A ; ; else TwoPowe ; m A; while m >, m m/4; TwoPowe *TwoPowe ;ed while m <.5, m m*4; TwoPowe TwoPowe/;ed (+*m)/3; fo k :4 (+ (m/))/; ed *TwoPowe; ed
clc; close all; clea all; foma log e; fame 'fc'; a ip('ee a ale:'); b ip('ee b ale:'); c ip('ee saig ale:'); ma c; mi c; fc feal(fame,c,a,b); dela.; fpc (feal(fame,c+dela,a,b)-fc)/dela; k; disp(spif('k fal fpal ')) while ip('newo sep? (o, yes)') kk+; (k) c; y(k) fc; ew c fc / fpc; c ew; fc feal(fame,c,a,b); fpc (feal(fame,c+dela,a,b)-fc)/dela; disp(spif('%.f %.5f %.5f %.5f',k,c,fc,fpc)) if ma < (k); ma (k); ed if mi > (k); mi (k); ed ed lispace(mi,ma,); y feal(fame,,a,b); plo(,y,'-',,y,'*') Ee a ale:. Ee b ale:.5 Ee saig ale: k fal Newo sep? (o, yes) -.454545455995.8975644793 -.486579595.3499895835 3 -.48646735955.6877535 4 -.486464797.76 5 -.4864647945. Newo sep? (o, yes) 3
% scip zeoi % ses malab bili oofide "ZERO" % o fid a zeo of a fcio 'fame' close all; clea all; foma log %fame 'fc'; % se defied fcio-ca also gie as @fc %fpame'dfc'; % se def. deiaie-o eqied by ZERO del.; % fcio ale limiig oleace a ip('ee a ale:'); b ip('ee b ale:'); lispace(-,,); y feal(@fc,,a,b); c ip('ee saig ale:'); %oo fzeo(@fc,c,.,,a,b); % gadfaheed foma OPTIONSopimse('MaIe',,'Tol',del,'TolX',del^); oo fzeo(@fc,c,options,a,b) y feal(@fc,oo,a,b) plo(,y,oo,y,'*') 4
The Seca ieaio fo locaig zeos fp f ( ) ( ) _ f ( _ ) f ( ) f ( _ ) f ( ) _ % scip SEC.M: ses seca mehod o fid zeo of UNC.M close all; clea all; clc; foma log e fame 'fc'; a ip('ee a:');b ip('ee b:'); c ip('ee saig ale:'); fc feal(fame,c,a,b); del.; k; disp(spif('k fal fpal ')) fpc (feal(fame,c+dela,a,b)-fc)/dela; while ip('seca sep? (o, yes)') kk+; (k) c; y(k) fc; f_ fc; ew c - fc/fpc; _ c; c ew; fc feal(fame,c,a,b); fpc (fc - f_)/(c-_); disp(spif('%.f %.5f %.5f %.5f',k,c,fc,fpc)) ed if () < (k); a floo(()-.5); b ceil((k)+.5); else; b floo(()-.5); a ceil((k)+.5); ed lispace(a,b,);yfeal(fame,,a,b);plo(,y,,y,'*') 5
Applicaio: solio of a BVP (Boday Vale Poblem) d y d y y + k y ( ) ; y( π ) + y' ( π ) ( ) Asi( k) ( kπ ) + k ( kπ ) si Solio Poblem (HW 5) Sole peios eqaio fo he smalles siable ozeo ale of k (eigeale) sig (a) The Newo mehod (scip NEWT.M ) (b) The bil-i Newo mehod (scip ZEROIN.M ) (c) The seca mehod (scip SEC.M ) 6
fcio f fc(,a,b) % ap ea % fo ieesig behaio, se a., b.,.4 f.5*.^+ *.^8 - a*.^6 + b; Newo s mehod fo oliea sysems: shoo dow he bogey! e [,, h] ( ), g 7
8 Eqaios of moio () () () h z y () ( ) () ( ) () ( ) ( ) si si g z y + iade defede ( ) ( ) ( ) ( ) ( ) + + δ δ δ Newo s mehod fo d o 3d fcios
9 o ballisic eample: ( ) ( ) ( ) ( ) ( ) + 3 3 3 3 si si h g z z y y ( ) ( ) ( ) ( ) ( ) ( ) si si si si si si Ieae, saig wih a siable gess, say: 4 / / π π ( ) δ
Pojec 5-a Add a small och of ealism: he cao eqies a fiie amo of ime o be ed o he fiig diecio. The ime depeds o he eac oaio. Ths, yo ms fige o a opimal oaio ais ad pefom a oaio ha is as fas as possible (gie he fied oaioal speed of he cao). The ballisic solio shold ake acco of he ime eqied fo he oaio, sice he fiig agles deemie he ime eqied fom he mome yo decide o fie o he mome he cao ca acally fie o he mome whe iecep is achieed. Specifically, he simlaio iese is a cbic bo wih a edge of legh of miles. A ime a bogey ees a he poi (,y,z) (,,h) moig i he posiie -diecio wih speed. The cao is siaed a he poi (,, ) ad pois iiially a a diecio chaaceized by agles (, ). As he bogey pogesses yo scip shold ask yo whehe yo wa o shoo i dow. If yo aswe ``o (), i shold adace he bogey by click ad ask agai. If yo aswe ``yes () he shoo-dow pocess shold ge saed. The cao shold adace fom is idle posiio o is fiig posiio by he bes oaio (which yo ms compe!). Is moio shold be show by a sccessio of images, whee cae shold be ake
o podce he sese of moio (e.g. ehibi ce 3 posiio as a aow ad peios posiio as a boke lie). Whe he cao eaches is fiig posiio i shold fie a pojecile. om ha poi o he cao sops ad he pogam shold display he pojecile ad bogey by appopiae symbols, adacig alog hei especie ajecoies each a is ow speed. Whe coac is achieed, a appopiae symbol shold be displayed ad saisics pied (e.g. ime ad locaio of iecep, fiig agles ec.). If a iecep solio is impossible a he poi yo decide o fie, he pogam ogh o op a faile comme (sch as: ``iecep impossible-abo lach ec.) ad he bogey shold complee is ajecoy eiig he domai (o hiig a age, if yo feel like addig fhe gaphic ealism o yo simlaio. 4 I ha case, he age is he eie plae. (Opioal: he age is locaed a he poi (,y,z) (,5,.) ad he bogey ees as befoe b i has a saigh lie moio headig fo he age. Oce yo specify he ajecoy of he bogey, all else woks as i he iial case of -paallel moio! o his case, he ey poi is a adom poi o he plae, ad he speed is dieced alog he saigh lie joiig he ey poi ad he age.) Yo shold i a caoo of yo simlaio, wih a sccessio of images i a comic book foma. Yo op shold gie a complee ad clea pice of wha is happeig as ime adaces.
ω α g 5 Aimig iiially a agles: Ms o agles: Toal oaio by agle: The ime eqied eqals: Gie agla speed: ( ), α ω (, ) α /ω T Iiial codiios ad ohe cosas 6 ( + 4* ad () )*.3( mi / sec) h.+ 9.9* ad().4 ( mi / sec) π ω sec 6 g 3. f / sec
ied-ale paamees 7,, ae bil-i cosas Sccess codiio 5 ( ) + + f 3 Discssio: modifyig he eqaios o acco fo he ig ime T + T T α, ( ) (, ) (, ) ω ( α ) (, ) ( ), 8 (, ) [, si, si] 3
Sice he lach ime ow depeds o he agles, he paial deiaies wih espec o he agles ms ow eflec ha depedece. o eample: ( + ( ) ) si ( ) 9 α ω α ( + si si ) + si si α α siα siα α 4
( α ) ( ( + si si )) ( + si si ) ( si + si ) MINBND Scala boded oliea fcio miimizaio. X MINBND(UN,,) sas a X ad fids a local miimize X of he fcio UN i he ieal < X <. UN acceps scala ip X ad es a scala fcio ale ealaed a X. 5
SPLINE Cbic splie daa iepolaio. YY SPLINE(X,Y,XX) ses cbic splie iepolaio o fid YY, he ales of he delyig fcio Y a he pois i he eco XX. The eco X specifies he pois a which he daa Y is gie. If Y is a mai, he he daa is ake o be eco-aled ad iepolaio is pefomed fo each colm of Y ad YY will be legh(xx)-by-size(y,). PP SPLINE(X,Y) es he piecewise polyomial fom of he cbic splie iepola fo lae se wih PPVAL ad he splie iliy UNMKPP. Odiaily, he o-a-ko ed codiios ae sed. Howee, if Y coais wo moe ales ha X has eies, he he fis ad las ale i Y ae sed as he edslopes fo he cbic splie. Namely: f(x) Y(:,:ed-), df(mi(x)) Y(:,), df(ma(x)) Y(:,ed) Eample: This geeaes a sie ce, he samples he splie oe a fie mesh: :; y si(); :.5:; yy splie(,y,); plo(,y,'o',,yy) PPVAL Ealae piecewise polyomial. V PPVAL(PP,XX) es he ale a he pois XX of he piecewise polyomial coaied i PP, as cosced by SPLINE o he splie iliy MKPP. V PPVAL(XX,PP) is also accepable, ad of se i cojcio wih MINBND, ZERO, QUAD, ad ohe fcio fcios. Eample: Compae he esls of iegaig he fcio ad his splie: a ; b ; i qad(@,a,b,[],[]); a : b; y (); pp splie(,y); i qad(@ppal,a,b,[],[],pp); i poides he iegal of he ie fcio oe he ieal [a,b] while i poides he iegal oe he same ieal of he piecewise polyomial pp which appoimaes he ie fcio by iepolaig he comped,y ales. 6