Numerically solve equations with variables inside numerical integration

2 views (last 30 days)
I am trying to solve equations in a form of
where C1, C2, C3 are known and , M, F are variables to be solved. I have tried fsolve() like (below is definitely a simplified version for better illustration)
x = fsolve(@tobesolve,[0,0,0])
function rei = tobesolve(mud,M,F)
rei(1) = integral2(@(p,theta)intfun1(p,theta,mud,M,F),0,631,0,pi)-600;
rei(2) = integral2(@(p,theta)intfun2(p,theta,mud,M,F),0,631,0,pi)-400;
rei(3) = integral2(@(p,theta)intfun3(p,theta,mud,M,F),0,631,0,pi)-200;
end
function i1 = int1(p,theta,mud,M,F)
i1 = p+theta+mud+M+F;
end
function i2 = int2(p,theta,mud,M,F)
i2 = p-theta-mud-M-F;
end
function i3 = int3(p,theta,mud,M,F)
i3 = p+theta-mud+M-F;
end
What is unexpected is that the error read
>> main
函数或变量 'M' 无法识别。
出错 main>@(p,theta)int1(p,theta,mud,M,F) (24 )
rei(1) = integral2(@(p,theta)int1(p,theta,mud,M,F),0,631,0,pi)-600;
出错 integral2Calc>integral2t/tensor (228 )
Z = FUN(X,Y); NFE = NFE + 1;
出错 integral2Calc>integral2t (55 )
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
出错 integral2Calc (9 )
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
出错 integral2 (105 )
Q = integral2Calc(fun,xmin,xmax,yminfun,ymaxfun,opstruct);
出错 main>tobesolve (24 )
rei(1) = integral2(@(p,theta)int1(p,theta,mud,M,F),0,631,0,pi)-600;
出错 fsolve (264 )
fuser = feval(funfcn{3},x,varargin{:});
出错 main (21 )
x = fsolve(@tobesolve,[0,0,0])
原因:
Failure in initial objective function evaluation. FSOLVE cannot continue.
I wonder why M is undefined, although I have provided guess values and the same error does not affect mud.
And how to solve such equations with numeric integration in MATLAB.

Accepted Answer

Torsten
Torsten on 19 Aug 2022
x = fsolve(@(y)tobesolve(y(1),y(2),y(3)),[0,0,0])
instead of
x = fsolve(@tobesolve,[0,0,0])
And the function names must be intfun1, intfun2 and intfun3, not int1, int2 and int3.
  3 Comments
Torsten
Torsten on 19 Aug 2022
Edited: Torsten on 19 Aug 2022
x = fsolve(@tobesolve,[0,0,0])
expects the input to tobesolve to be the standard input, i.e. a vector of length 3.
But your input are 3 scalars of length 1.
How should the solver know this if you don't tell him in advance by modifying the input list as
@(y)tobesolve(y(1),y(2),y(3))
?

Sign in to comment.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!