How to deal with integration variable when using fsolve

Hello everyone! I have defined a vector of three functions F = [f(1); f(2); f(3)] with three unknown variables (z_s, W_s and W_m, computing the vector x) for which I want to solve for. The clue is, that two of these functions have one of the unknown variable (z_s) as their lower bound of an integral. I used the "int" command and stated my integration variable z as well as the unknown lower bound as z_s (and the upper bound of course). In a first attempt I forgot to define my integration variable, getting the Error: Undefined function or variable 'z'. Therefore, I stated z together with all my parameters:
>> k=3; t=1.1; f=1.5; f_x=1.5; C=1; e=3; o=2; U=1; M=2; H=1; syms x z;
g=@(x)laborcutofffunc(x,z,k,t,f,f_x,e,o,C,U,M,H); x0=[1.5 1.5 1];
[x,fval]=fsolve(g,x0)
Error using fsolve (line 258) FSOLVE requires all values returned by user functions to be of data type double.
I can understand the objective of the error message, but I wonder how I have to "deal" with the integration variable z instead. Or do I have to address my problem in another way? Thanks for your help.
Here is my function:
function F = laborcutofffunc(x,z,k,t,f,f_x,e,o,C,U,M,H); z_s=x(1); W_s=x(2); W_m=x(3);
F = [(int((1 + ((z+1)/2)*W_m.^(1-o) + z*W_s.^(1-o)).^((e-o)/(o-1)) * k*z.^(-k-1),z,z_s,inf) + t.^(1-e)*int((1 + ((z+1)/2)*W_m.^(1-o) + z*W_s.^(1-o)).^((e-o)/(o-1)) * k*z.^(-k-1),z,((C*(1/f_x) - z_s.^(-k)*(f/f_x)).^(-(1/k))),inf)) / (int(z*W_s.^(-o) * (1 + ((z+1)/2)*W_m.^(1-o) + z*W_s.^(1-o)).^((e-o)/(o-1)) * k*z.^(-k-1),z,z_s,inf) + t.^(1-e)*int(z*W_s.^(-o) * (1 + ((z+1)/2)*W_m.^(1-o) + z*W_s.^(1-o)).^((e-o)/(o-1)) * k*z.^(-k-1),z,((C*(1/f_x) - z_s.^(-k)*(f/f_x)).^(-(1/k))),inf)) - (U/H); (int((1 + ((z+1)/2)*W_m.^(1-o) + z*W_s.^(1-o)).^((e-o)/(o-1)) * k*z.^(-k-1),z,z_s,inf) + t.^(1-e)*int((1 + ((z+1)/2)*W_m.^(1-o) + z*W_s.^(1-o)).^((e-o)/(o-1)) * k*z.^(-k-1),z,((C*(1/f_x) - z_s.^(-k)*(f/f_x)).^(-(1/k))),inf)) / (int(((z+1)/2)*W_m.^(-o) * (1 + ((z+1)/2)*W_m.^(1-o) + z*W_s.^(1-o)).^((e-o)/(o-1)) * k*z.^(-k-1),z,z_s,inf) + t.^(1-e)*int(((z+1)/2)*W_m.^(-o) * (1 + ((z+1)/2)*W_m.^(1-o) + z*W_s.^(1-o)).^((e-o)/(o-1)) * k*z.^(-k-1),z,((C*(1/f_x) - z_s.^(-k)*(f/f_x)).^(-(1/k))),inf)) - (U/M); t.^(1-e)*((1 + ((C*(1/f_x) - z_s.^(-k)*(f/f_x)).^(-(1/k)))*(W_m.^(1-o)/2 + W_s.^(1-o)) + (1/2)*W_m.^(1-o)) / (1 + z_s*(W_m.^(1-o)/2 + W_s.^(1-o)) + (1/2)*W_m.^(1-o))).^((e-1)/(o-1)) - (f_x/f)];

回答(1 个)

Either define z as "syms" and apply "vpa" on the results of "int" or define function handles for the functions to be integrated and use "integral" instead of "int".
Best wishes
Torsten.

1 个评论

Thank you for you answer. However, the "vpa" command didn't work but I found a link in the Matlab documentation from there to the "double" command which did in fact solve the problem.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by