Asked by David Campbell
on 17 Jul 2013

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

*No products are associated with this question.*

Answer by Matt J
on 17 Jul 2013

Accepted answer

Should be

x = fzero(@firstorder,x0);

David Campbell
on 17 Jul 2013

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?

Matt J
on 17 Jul 2013

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

Log in to comment.

Answer by Youssef Khmou
on 17 Jul 2013

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])

Log in to comment.

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments

Log in to comment.