EDU>syms x y EDU>f = x*cos(x+y)-exp(x*y) f = x*cos(x+y)-exp(x*y) EDU>fx = diff(f,x) fx = cos(x+y)-x*sin(x+y)-y*exp(x*y) EDU>int(f,x) ans = cos(x+y)+(x+y)*sin(x+y)-y*sin(x+y)-1/y*exp(x*y) EDU>int(f,y) ans = x*sin(x+y)-1/x*exp(x*y) EDU>subs(f,{x y},{0 1}) ans = -exp(0) EDU>double(subs(f,{x y},{0 1})) ans = -1 % Older versions of Matlab may require you to type fin = inline(vectorize(f),'x','y') below % to specify that the variables are x and y. >> fin = inline(vectorize(f)) fin = Inline function: fin(x,y) = x.*cos(x+y)-exp(x.*y) >> fin(0,1) ans = -1 ------------------------------------------------ EDU>syms x y EDU>f=x-3/y f = x-3/y EDU>g = 3*y+x-7 g = 3*y+x-7 EDU>[a b] = solve(f,g) a = [ 7/2-1/2*13^(1/2)] [ 7/2+1/2*13^(1/2)] b = [ 7/6+1/6*13^(1/2)] [ 7/6-1/6*13^(1/2)] EDU>double([a b]) ans = 1.6972 1.7676 5.3028 0.5657 % So there are two solutions, (1.6972 1.7676) and (5.3028 0.5657) EDU>h=cos(x+y)-2^x+3 h = cos(x+y)-2^x+3 EDU>[a b]=solve(f,h) a = [ 2.6434937173776777045482256739744] [ 1.1348617854768247235753168714563] b = [ 1.1348617854768247235753168714563] [ 2.6434937173776777045482256739744] ---------------------------------------------- EDU>syms x y >> f = x^3-12*x+(x-y)^2+7; >> fx = diff(f,x), fy = diff(f,y), fxx = diff(fx,x) fx = 3*x^2-12+2*x-2*y fy = -2*x+2*y fxx = 6*x+2 >> D = fxx*diff(fy,y) - diff(fx,y)^2 D = 12*x >> [ax ay] = solve(fx,fy) ax = [ 2] [ -2] ay = [ 2] [ -2] >> T = [ ax ay subs(D, {x y }, {ax ay}) subs(fxx, {x y }, {ax ay }) ] T = [ 2, 2, 24, 14] [ -2, -2, -24, -10] >> % so from the above, (2,2) is a relative minimum and (-2,-2) is a saddle point. --------------------- >> syms x y z lam >> f = x^3-3*x^2+2*y^2+z^2; >> g = 2*x^2+y^2+z^2; >> fx = diff(f,x), fy = diff(f,y), fz = diff(f,z) fx = 3*x^2-6*x fy = 4*y fz = 2*z >> gx = diff(g,x), gy = diff(g,y), gz = diff(g,z) gx = 4*x gy = 2*y gz = 2*z >> [alam ax ay az] = solve( fx-lam*gx, fy-lam*gy, fz-lam*gz, g-1 ) alam = [ 3/8*2^(1/2)-3/2] [ -3/8*2^(1/2)-3/2] [ 2] [ 2] [ 2] [ 2] [ 1] [ 1] [ 1] [ 1] ax = [ 1/2*2^(1/2)] [ -1/2*2^(1/2)] [ 0] [ 0] [ 14/3] [ 14/3] [ 0] [ 0] [ 10/3] [ 10/3] ay = [ 0] [ 0] [ 1] [ -1] [ 1/3*i*383^(1/2)] [ -1/3*i*383^(1/2)] [ 0] [ 0] [ 0] [ 0] az = [ 0] [ 0] [ 0] [ 0] [ 0] [ 0] [ 1] [ -1] [ 1/3*i*191^(1/2)] [ -1/3*i*191^(1/2)] >> [bx by bz] = solve( fx,fy,fz ) bx = [ 0] [ 2] by = [ 0] [ 0] bz = [ 0] [ 0] >> [cx cy cz] = solve( gx, gy, gz) cx = 0 cy = 0 cz = 0 >> T = [ ax ay az subs(g, {x y z }, {ax ay az}) subs(f, {x y z }, {ax ay az }) bx by bz subs(g, {x y z }, {bx by bz }) subs(f, {x y z }, {bx by bz }) cx cy cz subs(g, {x y z }, {cx cy cz }) subs(f, {x y z }, {cx cy cz }) ] T = [ 1/2*2^(1/2), 0, 0, 1, 1/4*2^(1/2)-3/2] [ -1/2*2^(1/2), 0, 0, 1, -1/4*2^(1/2)-3/2] [ 0, 1, 0, 1, 2] [ 0, -1, 0, 1, 2] [ 14/3, 1/3*i*383^(1/2), 0, 1, -1318/27] [ 14/3, -1/3*i*383^(1/2), 0, 1, -1318/27] [ 0, 0, 1, 1, 1] [ 0, 0, -1, 1, 1] [ 10/3, 0, 1/3*i*191^(1/2), 1, -473/27] [ 10/3, 0, -1/3*i*191^(1/2), 1, -473/27] [ 0, 0, 0, 0, 0] [ 2, 0, 0, 8, -4] [ 0, 0, 0, 0, 0] >> double (T) ans = 0.7071 0 0 1.0000 -1.1464 -0.7071 0 0 1.0000 -1.8536 0 1.0000 0 1.0000 2.0000 0 -1.0000 0 1.0000 2.0000 4.6667 0 + 6.5235i 0 1.0000 -48.8148 4.6667 0 - 6.5235i 0 1.0000 -48.8148 0 0 1.0000 1.0000 1.0000 0 0 -1.0000 1.0000 1.0000 3.3333 0 0 + 4.6068i 1.0000 -17.5185 3.3333 0 0 - 4.6068i 1.0000 -17.5185 0 0 0 0 0 2.0000 0 0 8.0000 -4.0000 0 0 0 0 0 >> double(T([1,2,3,4,7,8,11,13],[1,2,3,5])) ans = 0.7071 0 0 -1.1464 -0.7071 0 0 -1.8536 0 1.0000 0 2.0000 0 -1.0000 0 2.0000 0 0 1.0000 1.0000 0 0 -1.0000 1.0000 0 0 0 0 0 0 0 0 ------------------------------------------------------------------------------------ % Following is a telnet session solving problem #3 on the second exam % I telnetted to wam.umd.edu. % It seems you must first give the command tap matlab, % after which you can type the command matlab. % Note- If you know what you are doing you may even be able to do % graphics in matlab from the comfort of your dorm room. % In Linux you should be able to ssh to wam and be able to see graphics. % In Mac OSX you can install XDarwin and do the same (I have tested this) % Probably in Windows you can install an X server which will allow you to do the same also. No mail. There is unread WAMnews. Read (y/n)? n rac2.wam.umd.edu-16: tap matlab ---------------------------------------------------------------------- Sun Sep 8 01:46:27 EDT 2002 ***** Matlab 6.5 (Release 13) is available for testing. ***** ***** To use, "tap matlab65" ***** This is Matlab version 6.1 (aka Release 12.1). This version does NOT run on DU 4.0d machines. Please upgrade to DU 4.0f if you want to run matlab on your Dec Alpha machine. To start, type "matlab" The previous version (5.3.1) is available as "tap matlab531" ---------------------------------------------------------------------- rac2.wam.umd.edu-17: matlab < M A T L A B > Copyright 1984-2001 The MathWorks, Inc. Version 6.1.0.450 Release 12.1 May 18 2001 Warning: Directory access failure: /afs/glue.umd.edu/department/enee/software/femlab/femlab22/femlab. Warning: Directory access failure: /afs/glue.umd.edu/department/enee/software/femlab/femlab22/autoctrl. Warning: Directory access failure: /afs/glue.umd.edu/department/enee/software/femlab/femlab22/sme. Warning: Directory access failure: /afs/glue.umd.edu/department/enee/software/femlab/femlab22. To get started, type one of these: helpwin, helpdesk, or demo. For product information, visit www.mathworks.com. >> syms x y z lam >> f = (x-1)^2+y^2 f = (x-1)^2+y^2 >> g = x^2+3*y^2 g = x^2+3*y^2 >> fx=diff(f,x), fy=diff(f,y), gx= diff(g,x), gy=diff(g,y) fx = 2*x-2 fy = 2*y gx = 2*x gy = 6*y >> [alam ax ay] = solve(fx-lam*gx, fy-lam*gy,g-4) alam = [ 1/2] [ 3/2] [ 1/3] [ 1/3] ax = [ 2] [ -2] [ 3/2] [ 3/2] ay = [ 0] [ 0] [ 1/6*21^(1/2)] [ -1/6*21^(1/2)] >> [cx cy] = solve(gx,gy) cx = 0 cy = 0 % I'll define f and g as inline functions. % Then I can evaluate them without using the subs command. >> inf=inline(vectorize(f),'x','y') inf = Inline function: inf(x,y) = (x-1).^2+y.^2 >> ing=inline(vectorize(g),'x','y') ing = Inline function: ing(x,y) = x.^2+3.*y.^2 >> T=[ax ay ing(ax,ay) inf(ax,ay); cx cy ing(cx,cy) inf(cx,cy)] T = [ 2, 0, 4, 1] [ -2, 0, 4, 9] [ 3/2, 1/6*21^(1/2), 4, 5/6] [ 3/2, -1/6*21^(1/2), 4, 5/6] [ 0, 0, 0, 1] % Since g(0,0)=0 we should ignore the last point above. % (This means grad g is never 0 when g=4). % So we see the minimum occurs at (3/2, +- sqrt(21)/6 )