Why does fsolve not return the correct solution?

5 vues (au cours des 30 derniers jours)
Radu Bors
Radu Bors le 21 Mar 2020
Commenté : Radu Bors le 23 Mar 2020
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 commentaire
Walter Roberson
Walter Roberson le 21 Mar 2020
It would help if we had your data to test with.

Connectez-vous pour commenter.

Réponse acceptée

darova
darova le 21 Mar 2020
The problem is that you are not passing E variable into f function
Solution
See more HERE

Plus de réponses (0)

Catégories

En savoir plus sur Testing Frameworks dans Help Center et File Exchange

Tags

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by