I'm trying to get a numerical value from a function using quad. In a separate .m-file I got a function looking like this:
function Wi = Wifun(y,T,TM,TMO,G2,A,b,x,Epsi,ny)syms G2;syms T;syms TM;syms TMO;syms ny;syms A;syms Epsi;syms b;syms x;syms y;G = G2.*(1+((T-300)./TM).*TMO);Ei = -(1/2.*pi).*((1+ny)./(1-ny)).*G.*A.*Epsi;Wi = -(2/3).*b.*x.*Ei.*(1./(x.^2+y.^2));
This function will produce this formula:
-(pi*A*Epsi*G2*b*x*((TMO*(T - 300))/TM + 1)*(ny + 1))/(3*(x^2 + y^2)*(ny - 1))
If I write like this:
syms yT = 1273;TM = 2163;TMO = -0.5;G2 = 126000;A = 1.2E-29;b = 0.000000000258;x = 2/3*b;Epsi = 0.00487903650119246;ny = 0.3;fun = @(y)-(pi.*A.*Epsi.*G2.*b.*x.*((TMO.*(T - 300))./TM + 1).*(ny + 1))./(3.*(x.^2 + y.^2).*(ny - 1));z2 = quad(fun,-2,2)
It works and z2 gets the value of 4.0641e-027. But if instead of the 2 last lines try to write like this:
z = quad(Wifun,-2,2)
There will be this error:
??? Error using ==> fcnchk at 108If FUN is a MATLAB object, it must have an feval method.Error in ==> quad at 66f = fcnchk(funfcn);Error in ==> test at 19z = quad(Wifun,-2,2)
Someone told me that you should write like this:
Wifun2 = str2func('Wifun');z = quad(Wifun2,-2,2)
But then the error looks like this instead:
??? Undefined function or method 'isfinite' for input arguments of type 'sym'.Error in ==> quad at 81if ~isfinite(y(1))Error in ==> test at 19z = quad(Wifun2,-2,2)
Is there someone here that knows how I can do this?
Best Answer