Plotting graph from non linear equation in MATLAB

I need help while plotting a non linear equation like:
*(plotting of "x Vs a"; x: Y-axis, a: X-axis)
x = b*(a-c-x) +(2*b*(a-c-x) +d)*(log(R) - (1/2)*log((R^2)*(1+(2*b/d)*(a-c-x))))
where,
a = 0:0.01:2
b = 1.577*10^11
c = 0.74
d = 1.9296*10^(-7)
R = 5*10^(-9)
I'm facing error while using solve & fzero function.

 採用された回答

Torsten
Torsten 2022 年 3 月 8 日

1 投票

A = 0:0.01:2;
b = 1.577e11;
c = 0.74;
d = 1.9296e-7;
R = 5e-9;
x0 = -1.0;
for i = 1:numel(A)
a = A(i);
fun = @(x) -x + b*(a-c-x) +(2*b*(a-c-x) +d).*(log(R) - (1/2)*log((R^2)*(1+(2*b/d)*(a-c-x))));
X(i) = fsolve(fun,x0);
x0 = X(i);
end
plot(A,X)

7 件のコメント

Supriya Khatoniar
Supriya Khatoniar 2022 年 3 月 8 日
Thank you very much, got my mistake. I may contact if I face any other problems.
Supriya Khatoniar
Supriya Khatoniar 2022 年 3 月 9 日
I have an doubt in the above code: whether "a" will take all the values or it will take only the final value from the array? as its value is showing as 2, not the full array.
Torsten
Torsten 2022 年 3 月 9 日
If you output "a" in the for-loop, you will see that it takes all values stored in the A-array one by one.
Then, the scalar "a" is used to define the function "fun". The solution x for the specific a-value is then saved in the array X as X(i).
Supriya Khatoniar
Supriya Khatoniar 2022 年 3 月 9 日
Ohh, yes, just checked. Thanks a lot!
Supriya Khatoniar
Supriya Khatoniar 2022 年 3 月 31 日
Can you help me out to solve the above equation using Newton-Raphson iterative approach? or are there any other approaches to solve non linear equation like this?
Torsten
Torsten 2022 年 3 月 31 日
So the solution from fsolve was not fine ?
Supriya Khatoniar
Supriya Khatoniar 2022 年 4 月 1 日
That was fine, finding some other ways as well..

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by