《高等应用数学问题的MATLAB求解》——第6章习题代码

(1)

>> syms x y z;
>> f1(x,y,z)=24*x*y-x^2-y^2-x^2*y^2-13;
>> f2(x,y,z)=24*x*z-x^2-z^2-x^2*z^2-13;
>> f3(x,y,z)=24*y*z-y^2-z^2-y^2*z^2-13;
>> [x0,y0,z0]=vpasolve(f1,f2,f3);
>> norm(f1(x0,y0,z0)),norm(f2(x0,y0,z0)),norm(f3(x0,y0,z0))
>> syms x y z;
>> f1(x,y,z)=x^2*y^2-z*x*y-4*x^2*y*z^2-x*z^2;
>> f2(x,y,z)=x*y^3-2*y*z^2-3*x^3*z^2-4*x*z*y^2;
>> f3(x,y,z)=y^2*x-7*x*y^2+3*x*z^2-x^4*z*y;
>> [x0,y0,z0]=vpasolve(f1,f2,f3);
>> norm(f1(x0,y0,z0)),norm(f2(x0,y0,z0)),norm(f3(x0,y0,z0))

(2)

(3)

>> syms x;f(x)=exp(-(x+1)^2+pi/2)*sin(5*x+2);
>> ezplot(f(x))
>> line([-3.5,1.5],[0,0]);
>> norm(double(f(x0)))

>> syms x y;
>> f(x,y)=(x^2+y^2+10*x*y)*exp(-x^2-y^2-x*y);
>> g(x,y)=x^3+2*y-4*x-5;
>> ezplot(g); hold on;ezplot(f)
>> x1=2.491364;y1=-0.251406;x2=-0.210008599;y2=2.084736302;
>> double(norm(f(x1,y1)-g(x1,y1),f(x2,y2)-g(x2,y2)))

(4)

>> syms x;
>> f=exp(-(x+1)^2+pi/2)*sin(5*x+2);
>> x0=vpasolve(f); subs(f,x,x0)

>> f=@(p)(p(1)^2+p(2)^2+10*p(1)*p(2))*exp(-p(1)^2-p(2)^2-p(1)*p(2));
>> f=@(p)[(p(1)^2+p(2)^2+10*p(1)*p(2))*exp(-p(1)^2-p(2)^2-p(1)*p(2));p(1)^3+2*p(2)-4*p(1)-5];
>> ff=optimset;ff.TolX=1e-16;ff.TolFun=1e-30;ff.MaxFunEvals=2e+03;ff.MaxIter=4e+04;
>> [t,h]=fsolve(f,[2,0],ff)

(5)

>> more_sols(f,zeros(1,1,0),100+100i),X

(30)

( a )

>> aa=[1 1 1 2 2 3 3 4 5 5 5 6 6 7 8 8];
>> bb=[2 4 5 3 5 5 7 8 4 6 8 7 9 9 6 9];
>> ab=[2 9 6 1 3 1 6 4 2 9 7 5 1 5 1 5];
>> R=sparse(aa,bb,ab);R(9,9)=0;%不懂为什么要R(9,9)???
>> h=view(biograph(R,[],'ShowWeights','on'))
>> [d,p]=graphshortestpath(R,1,9)
>> set(h.Nodes(p),'Color',[1,0,0])
>> edges=getedgesbynodeid(h,get(h.Nodes(p),'ID'));
>> set(edges,'LineColor',[1,0,0])

( b )

>> a=[1 1 2 2 2 3 4 4 5 5 5 6 7 7 8 8 9 9 10 11];
>> b=[2 4 3 5 6 6 5 7 6 7 8 9 8 10 9 11 11 12 11 12];
>> w=[5 3 4 6 4 9 2 4 1 7 6 8 2 4 7 4 3 2 1 2];
>> R=sparse(a,b,w);R(12,12)=0;R=R+R';
>> h=view(biograph(R,[],'ShowWeights','on'))
>> [d,p]=graphshortestpath(R,10,3);
>> set(h.Nodes(p),'Color',[1,0,0])
>> edges=getedgesbynodeid(h,get(h.Nodes(p),'ID'));
>> set(edges,'LineColor',[1,0,0])

( 31 )

>> R=[  0,364,314,334,330,inf,253,287;
      364,  0,396,366,351,267,454,581;
      314,396,  0,232,332,247,159,250;
      334,300,232,  0,470, 50, 57,inf;
      330,351,332,470,  0,252,273,156;
      inf,267,247, 50,252,  0,inf,198;
      253,454,159, 57,273,inf,  0, 48;
      260,581,220,inf,156,198, 48,  0]
>> for k=2:8,k,[d0,p0]=dijkstra(R,1,k),end

( 32 )

>> a=[1 1 1 2 2 2 3 3 3 4 4 4 5 5 6 6 7 7 8 9];
>> b=[2 3 4 5 6 7 5 6 7 5 6 7 8 9 8 9 8 9 10 10];
>> w=10*[2 4 3 7 4 6 3 2 4 4 1 5 1 4 6 3 3 3 3 4];
>> R=sparse(a,b,w);R(20,20)=0;[d,p]=dijkstra(R,1,10)
原文地址:https://www.cnblogs.com/Math-Nav/p/13375095.html