have a question calculating integral

hello guys.
I set up the functions and try to solve the integral but a error has occured.
my code :
syms L;
syms W;
syms a;
syms q;
syms n;
syms m;
syms R;
q = H./L;
a = W./q;
b = (W*(1-R)/(2*q));
m = (0.01*(81.0*W^2 + 180.0*b*W))/a;
n=sqrt(a*m+b^2)-m-b;
syms x;
f=sqrt(a*x+b^2)-x-b;
h=W*0.9-x;
m=(0.01*(80.1*W^2+180.0*b*W)/a);
n=sqrt(a*m+b^2)-m-b;
syms t;
f=@(x) sqrt(a*x+b^2)-x-b;
g=@(x,t) (sqrt(a*t+b^2)-t-b)/t*x;
p=@(x,t) ((sqrt(a*t+b^2)-t-b)-n)/(t-m)*(x-m)+n;
a=integral (f,0,m)-integral (g,0,t)-integral(p,t,m);
and here, I want to calculate the total integral, but some error has occured..
how do I solve it?
thank you.

 Accepted Answer

You do not define H and you do not declare it symbolic.
You define g and p as function handles of two variables, but you pass them to integral() which expects a function handle of one variable to do a numeric integral of.
You try to integrate f to the upper limit m, but integral() is for numeric integrals and for numeric integrals you need numeric bounds.
Perhaps you want
a = int(f(x),x,0,m) - int(g(x,t),x,0,t) - int(p(x,t),x,t,m);
The result will be a piecewise() expression. It looks to me that is there due to the potential for a division by 0. For example your p(x,t) is undefined if L = 0 and we have no way to know that L is not permitted to be 0.

2 Comments

thank you so much!!
and now, I want to input 4 variable (W,H,L,R) and calculate the value of t when a'(t)=0
so below is my code
H=input('input the value of H');
W=input('input the value of W');
L=input('input the value of L');
R=input('input the value of R');
syms H;
syms L;
syms W;
syms a;
syms q;
syms n;
syms m;
syms R;
q = H./L;
a = W./q;
b = (W*(1-R)/(2*q));
m = (0.01*(81.0*W^2 + 180.0*b*W))/a;
n=sqrt(a*m+b^2)-m-b;
syms x;
f=sqrt(a*x+b^2)-x-b;
h=W*0.9-x;
m=(0.01*(80.1*W^2+180.0*b*W)/a);
n=sqrt(a*m+b^2)-m-b;
syms t;
f=@(x) sqrt(a*x+b^2)-x-b;
g=@(x,t) (sqrt(a*t+b^2)-t-b)/t*x;
p=@(x,t) ((sqrt(a*t+b^2)-t-b)-n)/(t-m)*(x-m)+n;
a=integral (f,0,m)-integral (g,0,t)-integral(p,t,m);
solve('derivate(@(t) a)=0');
when I entered this, I put the 4 values
but, the error has occurred...
how do I do after this..?
Thank you so much!!
After you define H and so on numerically, do not also "syms" those same variable names: doing so is like assigning a new value on top of the numeric value. Just leave them numeric.
You will need to use the int() version I showed, as you are expecting "a" to be a formula rather than a particular numeric result.
Once you have "a" in symbolic form, then
solve(diff(a,t)=0, t)

Sign in to comment.

More Answers (0)

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!