Title: Lessons from CST exercise
1Declaring/using a function for evaluation
Engr 0012 (04-1) LecNotes 14-01
2Finding maxima
no fmaxbnd command
can define new function
gtgt negfcn input('neg fcn name? gt ','s') neg
fcn name? neg_f13a
Engr 0012 (04-1) LecNotes 14-02
3Finding maxima
call fminbnd with negative of function
Engr 0012 (04-1) LecNotes 14-03
4Finding areas
easiest use quad or quadl
area quad(fname,xmin,xmax) or area
quadl(fname,xmin,xmax)
gtgt area1 quad(sfname,1.5,2.5) area1 0.1620
gtgt area2 quadl(mfname,1.5,2.5) area2 0.
1620
gtgt area3 quadl(ifname,0,pi) area3 0. 2086
can use any declaration form with quad or quadl
Engr 0012 (04-1) LecNotes 14-04
5Finding areas
more complex and not as accurate!!! use trapz
area trapz(xtrap,ytrap)
need to define x y vectors of points
numtraps 100 xtrap xlow(xhigh-xlow)/numtraps
xhigh if string x xtrap ytrap
eval(sfname,x) if m-file ytrap
feval(mfname,xtrap) if inline ytrap
feval(ifname,xtrap) area trapz(xtrap,ytrap)
Engr 0012 (04-1) LecNotes 14-05
6Finding ? f(x) dx over a range
objective is to create a vector of cumulative
area versus x value and then plot them on the
graph (i.e. area(x) vs x
create xpts for plotting xpts
xmin(xmax-xmin)/500xmax for i
11length(xpts) cumarea(i)
quad(fname,xpts(1),xpts(i)) end
plot cumulative area hold on
plot(xpts,cumarea,'g-')
Engr 0012 (04-1) LecNotes 14-06