Solve nonlinear equation with different parameters

조회 수: 2 (최근 30일)
letoppina
letoppina 2019년 2월 14일
댓글: Walter Roberson 2019년 2월 19일
Hello,
I would like to solve a (quite complicated) equation that looks like this:
pi/2*C*x + 0.5*(3 - gamma^2 - 2*gamma)*C*V^2 + 2*A*V + 2*x*B^2 - pi/2*F;
where gamma is also a function of x and it's defined as following:
gamma = gamma0*exp(-D*atan((B*x)./(C*Vdc)))*sqrt(1+((B*x)/(C*V)));
So, in the end, it can be considered as one (long) equation.
The unkowns are x and Vdc. I was thinking of defining the value of Vdc as a linsopace vector, for example, and see the value of x for each variation of Vdc (by making a loop). The question is: how can I solve the equation?
Also, would it be possible to solve the same equation by making varying other parameters of it (by making a loop on them)?
Thank you in advance for your help!

채택된 답변

Star Strider
Star Strider 2019년 2월 14일
Do something like this (although with the correct values for the constants):
A = 13;
B = 5;
C = 7;
D = 3;
F = 11;
V = 42;
gamma0 = 31;
gamma = @(x,Vdc) gamma0*exp(-D*atan((B*x)./(C*Vdc)))*sqrt(1+((B*x)/(C*V)));
eqn = @(x,Vdc) pi/2*C*x + 0.5*(3 - gamma(x,Vdc).^2 - 2*gamma(x,Vdc))*C*V^2 + 2*A*V + 2*x*B^2 - pi/2*F;
Vdc = linspace(0, 10, 5);
for k1 = 1:numel(Vdc)
xs(k1) = fsolve(@(x) eqn(x,Vdc(k1)), 1);
end
figure
plot(Vdc, xs)
grid
Experiment to get the result you want.
  댓글 수: 12
Star Strider
Star Strider 2019년 2월 19일
the order of magnitude of my solution has to be anyway between 10^-6 and 10^-4
True. However fsolve is a zero-finding function, so if you give it something very close to 0 initially, it is satisfied that it has solved the problem and stops iterating. The solution it arrives at is the value of the parameter of interest in your function that makes your function sufficiently close to 0.
You can change the various options with the optimoptions (link) function. However there is no need for you to do that, since fsolve is functioning normally, and delivers a reasonable result if you let it find the value of the parameter that results in your function being sufficiently close to 0.
Walter Roberson
Walter Roberson 2019년 2월 19일
Note that instead of passing a scalar x0 you can pass a vector with two elements; fsolve will only search within the given range. This does require that the function has a different sign at the two endpoints.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by