Why does fsolve not return the correct solution?

2 ビュー (過去 30 日間)
Radu Bors
Radu Bors 2020 年 3 月 21 日
コメント済み: Radu Bors 2020 年 3 月 23 日
I have an implicit function:
which I am trying to solve using fsolve to get the roots of the function f(j) below.
I know what my solutions should be from some experimental data. But when I run the code below to get the solution of the implicit function, it doesn't look at all correct.
E_data = sortrows(data(:,3))';
j_exp_data = sortrows(data(:,2))';
E = 0;
f = @(j)...
j_a * exp( (alpha_anod * z * Faraday_const) / (R_const * T) * (E - j*R - E_eq)) - ...
j_c * exp( -(alpha_cath * z * Faraday_const) / (R_const * T) * (E - j*R - E_eq)) - j;
for i = 1:length(E_data)
E = E_data(i);
[j_sol(i), fval(i), flag(i)] = fsolve(f, j_exp_data(i));
end
%%
figure
subplot(1,2,1)
plot(E_data, j_sol);
title("Implicit function solution");
grid on;
subplot(1,2,2)
plot(E_data, j_exp_data);
title("Experimental data");
grid on;
I'm getting some weird solution (see below). As a starting value for fsolve, I'm using the experimental value. I don't expect them to be exactly the same, but it should be close enough. Instead, I get completely off values:
The flag is always 1, with a tolerance of 1e-6. Does anyone know what am I doing wrong?
  1 件のコメント
Walter Roberson
Walter Roberson 2020 年 3 月 21 日
It would help if we had your data to test with.

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

採用された回答

darova
darova 2020 年 3 月 21 日
The problem is that you are not passing E variable into f function
Solution
See more HERE
  1 件のコメント
Radu Bors
Radu Bors 2020 年 3 月 23 日
That fixed it, thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTesting Frameworks についてさらに検索

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by