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

추가 답변 (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