I am having problems finding the roots of the following non linear discontinuous equation

Below is the code I am using, and the error message I recieve:
function y = firstorder(x)
mat = 'mnfepas';
props = material_data(mat);
S = props(1,3);
L = props(1,4);
J = props(1,5);
Tc = props(1,6);
Ns = props(1,8);
g = props(10);
T = 200;
B = 1;
muB = 9.27e-24; % units: Am^2 or J/T
kB = 1.3807e-23; % units: J/K
nu = 1.75;
y = (1/T)*(3*Tc*J*((0.5/J)*((2*J+1)*coth((J+0.5)*x/J)-coth(0.5*x/J)))/(J+1) + g*muB*J*B/kB + (9/5)*(((2*J+1)^4)-1)*Tc*nu*(((0.5/J)*((2*J+1)*coth((J+0.5)*x/J)-coth(0.5*x/J)))^3)/((2*J+2)^4))-x;
end
Then I use the following:
x0 = 3;
x = fzero(firstorder,x0);
And then I get the following error message:
Error using firstorder (line 21) Not enough input arguments.
Error in nonlinear_brillouin_solver (line 2) x = fzero(firstorder,x0);
the function y is discontinuous at zero due to the coth, and at some values of T the function will cross the x axis multiple times, so I should get multiple roots... i think
Any help would be greatly appreciated

 Akzeptierte Antwort

Should be
x = fzero(@firstorder,x0);

2 Kommentare

Thank you, does fzero work on discontinuous functions? My function has a discontinuity at x = 0, and also can it return more than one x value?
No fzero cannot return more than 1 value. The presence of discontinuities can definitely confuse fzero, as in the following example. You should therefore specify a search interval where the function is continuous.
>> fzero(@(x) 1/x,[-2,2])
ans =
-8.8818e-16

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

hi David,
if you have numerical values of the coefficients, you can use the function root instead as in this example :
6 x^3 - 4 x^2 + 10 x + 6 =0
R=roots([6 -4 10 6])

Kategorien

Mehr zu Optimization finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by