How do I numerically integrate a multivariable function wrt only one variable?

Hi guys,
I have a problem, since I want to numerically intergrate a multivariable function wrt only one variable. However, I only succeed by doing this with the following commands:
if true
clear
syms r s t
p0 = .75;
p1 = 3;
y0 = 720;
b = [5 -14 0.08];
end
if true
function demand = qn(x,b)
z1=b(1)+b(2)*x(1)+b(3)*x(2);
demand = z1;
end
if true
w(r,s) = int(qn([t, y0],b),t,r,s);
cs = w(p0,p1);
end
I know this is not a numerical integration. This returns me a symbolic variable (which I do not want), but this was the only way that I was able to retrieve some value. To clarify, I want to numerically integrate the function qn with respect to x(1) from p0 to p1. Could somebody help me with this please? Many thanks in advance! Cheers!

 采纳的回答

p0 = .75;
p1 = 3;
b = [5 -14 0.08];
x2=...
result = integral( @(x1) qn([x1,x2],b) , p0, p1)

4 个评论

The x2 should be the y0 of the example. Though when i try your example i get the following errors:
Error using integralCalc/finalInputChecks (line 526)
Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued' option to true.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in algorithm4 (line 19)
result = integral(@(x1)qn([x1,y0],b),p0,p1)
What do i miss?
Hmmmm. Sorry, it should be
p0 = .75;
p1 = 3;
y0 = 720;
b = [5 -14 0.08];
f=@(t) qn([t,y0],b);
g=@(p) arrayfun(f, p ) ;
result = integral( g , p0, p1)
In this case, it would be much easier if you wrote qn() with scalar arguments,
function demand = qn(t,y,b)
z1=b(1)+b(2)*t+b(3)*y;
demand = z1;
end
then this would work
result = integral( @(t) qn(t,y0,b) , p0, p1)
Thanks this works! I know that indeed with scalar arguments it would be easier, but it has to stay the way it is for other commands work (I did not include them in the post)

请先登录,再进行评论。

更多回答(0 个)

产品

版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by