Solve non-linear equation with varying value
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
I have a equation to solve
exp(-10*z)-9*exp(-2*z)+(8-4*x)=0
here
x=linspace(0,1,101)
Since the equation itself would change to a new equation for each x, i am unable to figure out how to solve it. I need to solve for z. Can somebody suggest an approach to this.
採用された回答
madhan ravi
2019 年 1 月 3 日
編集済み: madhan ravi
2019 年 1 月 3 日
x=linspace(0,1,101);
Result=cell(1,numel(x)); % preallocate
for i = 1:numel(x)
Result{i}=fzero(@(z) exp(-10*z)-9*exp(-2*z)+(8-4*x(i)),[0 5]);
% ^^^--initial guess interval
end
celldisp(Result)
[Result{:}] % double array
Gives:
>> [Result{:}]
ans =
Columns 1 through 7
0 0.0049 0.0096 0.0142 0.0187 0.0231 0.0274
Columns 8 through 14
0.0316 0.0357 0.0398 0.0438 0.0477 0.0517 0.0555
Columns 15 through 21
0.0594 0.0632 0.0670 0.0707 0.0744 0.0782 0.0818
Columns 22 through 28
0.0855 0.0892 0.0928 0.0964 0.1001 0.1037 0.1073
Columns 29 through 35
0.1109 0.1145 0.1181 0.1217 0.1252 0.1288 0.1324
Columns 36 through 42
0.1360 0.1396 0.1432 0.1468 0.1504 0.1540 0.1576
Columns 43 through 49
0.1612 0.1648 0.1685 0.1721 0.1758 0.1794 0.1831
Columns 50 through 56
0.1868 0.1905 0.1942 0.1979 0.2016 0.2054 0.2091
Columns 57 through 63
0.2129 0.2167 0.2205 0.2244 0.2282 0.2321 0.2359
Columns 64 through 70
0.2398 0.2438 0.2477 0.2517 0.2556 0.2596 0.2637
Columns 71 through 77
0.2677 0.2718 0.2759 0.2800 0.2842 0.2883 0.2925
Columns 78 through 84
0.2968 0.3010 0.3053 0.3096 0.3140 0.3183 0.3227
Columns 85 through 91
0.3272 0.3317 0.3362 0.3407 0.3453 0.3499 0.3545
Columns 92 through 98
0.3592 0.3640 0.3687 0.3735 0.3784 0.3833 0.3882
Columns 99 through 101
0.3932 0.3982 0.4033
>>
6 件のコメント
P K
2019 年 1 月 3 日
Hello Madan,Thanks for your response. But the z value should not be negative.
How you have decided that x0 =0 ? If i change x0, my answers would change. Can you explain a bit .
madhan ravi
2019 年 1 月 3 日
編集済み: madhan ravi
2019 年 1 月 3 日
Ravi Singh, x0 is the initial guess , why z shouldn't be negative ? , plot the graph to verify?
P K
2019 年 1 月 3 日
Because I have a plot which based on the above equation. The maximum value of Z=0.4(approx) at x=1.Thats why i am saying.
madhan ravi
2019 年 1 月 3 日
編集済み: madhan ravi
2019 年 1 月 3 日
x=linspace(0,1,101);
Result=cell(1,numel(x));
for i = 1:numel(x)
Result{i}=fsolve(@(z) exp(-10*z)-9*exp(-2*z)+(8-4*x(i)),[-5 5],optimoptions('fsolve','Display','off'));
% ^^---- change it to 0 if you only want the positive roots
end
celldisp(Result)
Note: When plotting the graph two roots were sighted , fsolve is able to find those two roots.
fplot(@(z) exp(-10*z)-9*exp(-2*z)+(8-4*1))
% ^--- from 0 to 1 with 101 points to verify the roots
xlim([-1 1]) % to see the roots clearly
ylim([-1 1])
grid on
See the below graph the two roots can be sighted :
>> Result{end}
ans =
-0.2339 0.4033 % as you said approximately 4 (the positive root)

madhan ravi
2019 年 1 月 3 日
編集済み: madhan ravi
2019 年 1 月 3 日
@Ravi Singh, See edited answer , if you got the answer to your question make sure to accept the answer else let know of your requirements which part is not clear.
madhan ravi
2019 年 1 月 3 日
Anytime :)
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Mathematics についてさらに検索
参考
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)
