Why does fsolve not return the correct solution?

2 visualizaciones (últimos 30 días)
Radu Bors
Radu Bors el 21 de Mzo. de 2020
Comentada: Radu Bors el 23 de Mzo. de 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?

Respuesta aceptada

darova
darova el 21 de Mzo. de 2020
The problem is that you are not passing E variable into f function
Solution
See more HERE

Más respuestas (0)

Categorías

Más información sobre Testing Frameworks en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by