Solve nonlinear equation with different parameters
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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
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 件のコメント
letoppina
2019 年 2 月 15 日
When computing, I get the following error:
Objective function is returning undefined values at initial point. FSOLVE cannot continue.
How should I proceed?
Walter Roberson
2019 年 2 月 15 日
編集済み: Walter Roberson
2019 年 2 月 18 日
don't start at 0. You divide by something times the current vdc value which generates a divide by 0 when the vdc is 0.
Star Strider
2019 年 2 月 15 日
@Walter — Thank you.
@letoppina — Note that the initial estimate I use here is 1.
letoppina
2019 年 2 月 18 日
Thanks, the error was on the initial condition (although the ouput is still not the one I expected..).
Moreover, if i want to make varying another variable involved in the equations (let's say for example B), should I just make another loop outside the existing one?
Star Strider
2019 年 2 月 18 日
As always, my pleasure.
‘... should I just make another loop outside the existing one?’
That is likely the best approach to change one other variable.
Hi,
sorry to bother again but I have another problem: when I compute, xs becomes a vector composed of values all equal to the initial condition (whatever I put in). Why?
Star Strider
2019 年 2 月 19 日
I have no idea.
What values are you using for the parameters?
Also, post your code.
here is the code I am using now (I have modified a little the equation involved since I am making a test but the pricniple should be the same):
clc
clear all
close all
f0 = 170;
w0 = 2*pi*f0;
beta = 0.1;
L = 28e-3;
C0 = 50e-9;
alpha = 1e-3;
C = 0.0219;
wsw = 1/(sqrt(L*C0));
Rsw = 200;
M = 20e-4;
acc = 0.2;
Fm = M*acc;
gamma0 = exp(-(Rsw*pi)/(2*L*wsw));
Vdc = linspace(0.1e-12, 20, 100);
eqn = @(x,Vdc) pi/2*C*w0.*x^2 + 1/2*C0*(1 - gamma0^2).*Vdc.^2 + Vdc.*2*alpha.*x - (1-gamma0)*C0.*Vdc.^2 - pi/2*Fm.*x;
for ii=1:length(Vdc)
xs(ii) = fsolve(@(x) eqn(x,Vdc(ii)), 0.01e-13)
end
figure
plot(Vdc, xs)
grid
Your initial estimate in your fsolve call is sufficiently close to 0 that your function is 0 there, satisfying the criteria fsolve uses as its convergence test.
You can change the convergence criterion using an options structure, however it’s easier to try a different starting value. You will get what appears to be an acceptable result with this call:
xs(ii) = fsolve(@(x) eqn(x,Vdc(ii)), 1);
letoppina
2019 年 2 月 19 日
Thank you for your answer. The reason I put such a small value as initial condition is because the order of magnitude of my solution has to be anyway between 10^-6 and 10^-4. How is it possible to change the convergence criterion?
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.
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 件)
カテゴリ
ヘルプ センター および File Exchange で Systems of Nonlinear Equations についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
