Search code examples
matlabwolfram-mathematica

change a m-file matlab into mathematica


I've written a matlab m-file to draw a double integral as below. Does everybody can show me its equivalent in mathematica???

tetha = pi/4;
lamb = -1;
h = 4;
tetha0 = 0;
syms x y l

n = [h.*((cos(tetha)).^2)./sin(tetha); h.*abs(cos(tetha)); 0];
ft = ((tetha - pi/2)./sin(tetha)).^4;
Rt = [cos(tetha) -sin(tetha); sin(tetha) cos(tetha)];
zt = [cos(tetha0) -sin(tetha0); sin(tetha0) cos(tetha0)];
lt = [x;y];

integrand = @(x,y)(ft.*h.*((abs(cos(tetha)).*      (x.*cos(tetha)-y.*sin(tetha)))-((cos(tetha)).^2/sin(tetha)).*(x.*sin(tetha)+y.*cos(tetha))));
PhiHat = @(a,b)(dblquad(integrand,0,a,0,b));
ezsurfc(PhiHat,[0,5,0,5])

Solution

  • Here you go (only minimal changes made), but you'll have to do your homework to understand function definitions, integration, plotting etc. in Mathematica. Also, this is not idiomatic Mathematica, but let's not go there...

    tetha=Pi/4;
    lamb=-1;
    h=4;
    tetha0=0;
    
    n={h*((Cos[tetha])^2)/Sin[tetha],h*Abs[Cos[tetha]],0};
    ft=((tetha-Pi/2)/Sin[tetha])^4;
    Rt={{Cos[tetha], -Sin[tetha]}, {Sin[tetha], Cos[tetha]}};
    zt={{Cos[tetha0], -Sin[tetha0]}, {Sin[tetha0], Cos[tetha0]}};
    
    integrand[x_,y_]:= (ft*h*((Abs[Cos[tetha]]*(x*Cos[tetha]-y*Sin[tetha]))-((Cos[tetha])^2/Sin[tetha])*(x*Sin[tetha]+y*Cos[tetha])));
    PhiHat[a_,b_]:=NIntegrate[integrand[x,y],{x,0,a},{y,0,b}];
    Plot3D[PhiHat[x,y],{x,0,5},{y,0,5}]
    

    enter image description here