MATLAB Answers


How to solve an equation in a certan interval.

Asked by Nuno
on 2 Dec 2012


syms w; % variable, that define the y axis
lam = 4*pi()^2 % constant, that define the x axis
tan(w/2) == w/2 - (4/(lam))*(w/2)^3 % equation

That equation with that constant has many solutions. What I pretend is to resolve the equation (maybe with solve) for lam = 4*pi()^2, in a certain interval of y, in order to catch a specific solution. For example, I know that for that constant there is a solution of w/pi() = 2 in the interval w/pi()=[1.5 2.5], (y axis).

I was trying with this:

syms w;
x = fsolve(@(w) tan(w/2) == w/2 - (4./(lam)).*(w/2).^3, [1.5*pi() 2.5*pi()]);

But is giving me some problems that I can´t resolve.

On Maple software the structure of the program is more or less the same, but it gives me the solutions that I want in specific intervals of y axis.

Matlab has to do it too or it doesn't?

Thanks to all.



No products are associated with this question.

1 Answer

Answer by Walter Roberson
on 2 Dec 2012
 Accepted answer

The function you provide to fsolve() needs to have a numeric result rather than a logical result. Convert your form A==B to (A)-(B) or (B)-(A)


on 8 Dec 2012

Now I'm confused again.


syms x;

a=fsolve(@(x) x.^2-4,[5 8])


Equation solved.

fsolve completed because the vector of function values is near zero as measured by the default value of the function tolerance, and the problem appears regular as measured by the gradient.

criteria details

a =

    2.0000    2.0000

Why the "fsolve" is returning 2 values, when I said that I want values in the interval [5 8]?

If I put an interval like [0 5] the fsolve gives me: a= 0 and 2, that is strange, right?

on 8 Dec 2012

In "fsolve" can you use an interval? because if you put a number in the place of the interval, the fsolve gives you one number, but if you put [number1 number2], it gives you two numbers. It is ridiculuos when you should get just one, the solution.

No, fsolve() does not take an interval. When you provide multiple values for x0 it becomes an equation with multiple variables. fzero() is the one that takes an interval.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!