I can't use "quadl"

4 views (last 30 days)
Serena
Serena on 30 Apr 2012
Hi, i'm trying to use the "quadl" to do an integration, but it just doesn't work, at the last 2 lines. Please help. Thanks.
a=1;
b=2;
kx=1;
ky=0;
k=sqrt((kx^2)+ky^2);
ka=k*a;
kb=k*b;
g=9.81;
A=1;
h=10;
z=0;
t=0;
omega=g*k*tanh(k*h);
elenum1=1;
elenum2=2;
elenum=(2*elenum1)+(elenum2);
node=elenum*2+1;
x0=a;
y0=a;
syms eta eta0 eta1 eta2
xeta1=eta;
yeta1=-y0;
xeta2=(b*(cos((eta-eta1)/b)))-x0;
yeta2=b*sin((eta-eta1)/b)-y0;
xeta3=-x0;
yeta3=b-eta-eta1-eta2-y0;
J1=abs(diff(yeta1,eta)*(xeta1)-(yeta1)*(diff(xeta1,eta)));
J2=abs(diff(yeta2,eta)*(xeta2)-(yeta2)*(diff(xeta2,eta)));
J3=abs(diff(yeta3,eta)*(xeta3)-(yeta3)*(diff(xeta3,eta)));
b11=((1/J1)*[diff(yeta1,eta),-diff(xeta1,eta)])';
b12=((1/J2)*[diff(yeta2,eta),-diff(xeta2,eta)])';
b13=((1/J1)*[diff(yeta3,eta),-diff(xeta3,eta)])';
b21=((1/J1)*[(-yeta1),(xeta1)])';
b22=((1/J2)*[(-yeta2),(xeta2)])';
b23=((1/J3)*[(-yeta3),(xeta3)])';
LS=(b-a)/(elenum1*2);
LC=(2*pi*b)/(2*elenum2*4);
eta1S=eta0+LS;
eta1C=eta0+LC;
eta2S=eta0+2*LS;
eta2C=eta0+2*LC;
N0S=[(((eta-eta1S)*(eta-eta2S))/(2*LS^2)),(((eta-eta0)*(eta-eta2S))/(-LS^2)),(((eta-eta0)*(eta-eta1S))/(2*LS^2))];
N0C=[(((eta-eta1C)*(eta-eta2C))/(2*LC^2)),(((eta-eta0)*(eta-eta2C))/(-LC^2)),(((eta-eta0)*(eta-eta1C))/(2*LC^2))];
B11=b11*N0S;
B12=b12*N0C;
B13=b13*N0S;
B21=b21*(diff(N0S,eta));
B22=b22*(diff(N0C,eta));
B23=b23*(diff(N0S,eta));
e01=(B11)'*B11*J1;
E01=quadl(@e01,eta0,eta1S);

Answers (1)

Walter Roberson
Walter Roberson on 30 Apr 2012
You cannot do numeric integration of a symbolic expression.
I would have suggested that you consider using matlabFunction() to turn the symbolic expression into a numeric function, but your integration bounds are symbolic, and it is not possible to do numeric integration with symbolic bounds.
Perhaps you are looking for int() instead of quadl() ?
  2 Comments
Serena
Serena on 30 Apr 2012
Hi, sorry to ask so many question but i am quite new to matlab.
I tried to use function as follow : but it doesn't allow too.
1) I put the function in the same script file :
function e01(eta,eta0,eta1,eta2)
e01=(B11)'*B11*J1;
E01=quadl(@e01,1,3);
??? function e01(eta,eta0,eta1,eta2)
|
Error: Function definitions are not permitted in this context.
2) I save the function in a different script file it gives me this:
??? Error using ==> e01
Too many output arguments.
Error in ==> quadl at 70
y = feval(f,x,varargin{:}); y = y(:).';
3) And when i place it in a different script file and insert values into it, it no longer reads my B11
I wrote this to test out : e01(3,4,4,2)
??? Undefined function or variable 'B11'.
Error in ==> e01 at 2
e01=(B11)'*B11*J1;
Can you please help. Thanks.
Walter Roberson
Walter Roberson on 30 Apr 2012
Make your main routine a function rather than a script.
In order to use B11 and J1 in your function e01, you would have to pass them in to the function, or you would have to use nested functions.
Your function e01 should be
function R = e01(eta,eta0,eta1,eta2)
R = (B11)'*B11*J1;
However, as best I recall, quadl will not pass in four arguments to the called function. What exactly is the point of passing anything in to the called function if you are going to ignore the values passed in?

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!