fsolve No solution found
이전 댓글 표시
matlab can not solve this nonlinear equation with one variable (ere)
function fval=eqn(ere)
P=(0.27);
er1=(1+1.8*10^14*1i);
er2=(2.5+2.5*10^-3*1i);
Hc=(10^6);
H=[0,2.5*10^4,5.0*10^4,7.5*10^4,1*10^5,1.3*10^5,1.5*10^5];
Pc=(0.33).*exp((-(H)/Hc));
c=(1-3*Pc).*(((P)./(Pc)).^Pc).*(((1-P)./(1-Pc)).^(1-Pc));
fval=((P).*((ere-er1)./(er1-2.*ere)))./((1)+(c).*((ere-er1)./(er1-2.*ere))+((1-P).*((ere-er2)./(er2-2.*ere)))./((1)+(c).*((ere-er2)./(er2-2.*ere))));
end
command use
options = optimoptions('fsolve','Display','iter');
[ere,fval] = fsolve(@eqn,[4.5;7.5],options);
solution not found
fsolve stopped because the last step was ineffective. However, the vector of function
values is not near zero, as measured by the value of the function tolerance.
<stopping criteria details>
fsolve stopped because the sum of squared function values, r, is changing by less
than options.FunctionTolerance = 1.000000e-06 relative to its initial value.
However, r = 4.174916e-03, exceeds sqrt(options.FunctionTolerance) = 1.000000e-03.
댓글 수: 9
dpb
2019년 5월 26일
>> eqn([4.5; 7.5])
ans =
-0.3530 + 0.0001i -0.3655 + 0.0001i -0.3785 + 0.0001i -0.3922 + 0.0001i -0.4067 + 0.0001i -0.4249 + 0.0001i -0.4377 + 0.0002i
-0.3874 + 0.0000i -0.4031 + 0.0001i -0.4199 + 0.0001i -0.4377 + 0.0001i -0.4566 + 0.0001i -0.4810 + 0.0001i -0.4983 + 0.0001i
>>
Your functional returns an array, not a 2-vector.
I'm guessing you intended for terms like (ere-ere1) to be (ere(1)-ere1) instead
Ammar Ahmed
2019년 5월 26일
But you haven't used the two values of the array ere to match up to the two specific local variables.
And, fsolve expects there to be as many returned values from the function as there are variables for which it is trying to solve -- in your case, two.
You should recast the solution to be two equations, best if one is for ere(1) the other for ere(2) if possible.
The excessive use of superfluous parentheses makes trying to read the equation difficult so I didn't spend much time trying to figure out just what it is that is attempted to be solved, sorry, only that the function as written doesn't identifiy which of the two-vector solution vector X is which and returns a 7x2 matrix instead of a two-vector.
ADDENDUM
Actually, what you likely need is to recast for the RE() and IM() parts; I'm not sure what fsolve does with complex variables but I'm guessing it's either using only the real part or, perhaps, the abs() value...and, in fact, the doc indicates it is only a vector X0 of reals for the starting point that it does accept so that's all that is being manipulated.
What do you expect to actually be solving for here?
dpb
2019년 5월 26일
[AA Answer moved to comment --dpb]
I'm trying to solve the effective permittivity ( dielectric constant) of composite material, i will try to solve it just for the real part ,
dpb
2019년 5월 26일
Reference to the formulation you're using, maybe??
I don't follow why H in your function has seven elements and why you're returning a matrix but I don't think you've got the function formulated correctly to do what you're wanting to do--but I'm not sure how to recast from just the code itself.
Walter Roberson
2019년 5월 27일
"fsolve expects there to be as many returned values from the function as there are variables for which it is trying to solve"
No, fsolve expects as many return values as there are equations. It is happy to deal with multivariate systems. For example,
fsolve(@(xy) (xy(1)-5).^2 + (xy(2)+2).^2, randn(1,2))
dpb
2019년 5월 27일
Good clarification, Walter...didn't writd what was intending to try to tell the OP -- he needs to recast to get the right number and probably (I'm guessing) needs to recast to have explicit solution for both real and imaginary components.
But I still can't figure out why he's returning the 2D array...
Walter Roberson
2019년 5월 27일
The output is length() of the input by length(H)
"this nonlinear equation with one variable (ere) "
[ere,fval] = fsolve(@eqn,[4.5;7.5],options);
The [4.5;7.5] tells MATLAB that you think it is a system with two variables rather than one.
H=[0,2.5*10^4,5.0*10^4,7.5*10^4,1*10^5,1.3*10^5,1.5*10^5];
Either there is a missing piecewise interpolation, or there is a missing sum() or prod()
If response to my "can't figure out", I grok the ML why; perhaps my presumption in writing same that OP understood and intended that was in error... :)
ADDENDUM
The idea that H may be intended as an interpolating vector is a good one, Walter...that hadn't occurred to me but I think you may be thinking in the right direction of where the solution needs to go. But, w/o the correlation he's trying to implement, it's a guess and the crystal ball is murky...as well as my recollections of complex permittivity from 50+ years ago are more than rusty.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Mathematics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!