Why does fsolve not return the correct solution?

2 次查看(过去 30 天)
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?

采纳的回答

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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Testing Frameworks 的更多信息

标签

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by