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

Thread Subject:
matlab solve function

Subject: matlab solve function

From: Anthony Hopf

Date: 2 Oct, 2010 01:20:29

Message: 1 of 6

I am trying to find the scan angles of an expanding beam as the scan angle increases, but I don't want any overlap from beam realization to beam realization. The beamwidth is a function of the scan angle. I was hoping to use the matlab solve function no dice. My next thought is to do this numerically, but I need to do it a bunch of time.

here is the code:
npa = 1.3;

bwaz = 2;

az1 = 0;

gamma = az1+(bwaz*cosd(az1)^npa)/2;

solve('az2 - (bwaz*cosd(az2)^npa)/2 - gamma = 0');

solving for az2, the next scan angle.

Thank you

Subject: matlab solve function

From: Anthony Hopf

Date: 2 Oct, 2010 01:55:08

Message: 2 of 6

I screwed up the code:

npa = 1.3;

bwaz = 2;

az1 = 0;

gamma = az1+(bwaz/cosd(az1)^npa)/2;

solve('az2 - (bwaz/cosd(az2)^npa)/2 - gamma = 0','az2');

still can't get it, I get this error:

Warning: Explicit solution could not be found.
> In solve at 98

Subject: matlab solve function

From: Roger Stafford

Date: 2 Oct, 2010 02:37:06

Message: 3 of 6

"Anthony Hopf" <anthony.hopf@gmail.com> wrote in message <i863ds$5r0$1@fred.mathworks.com>...
> I screwed up the code:
>
> npa = 1.3;
>
> bwaz = 2;
>
> az1 = 0;
>
> gamma = az1+(bwaz/cosd(az1)^npa)/2;
>
> solve('az2 - (bwaz/cosd(az2)^npa)/2 - gamma = 0','az2');
>
> still can't get it, I get this error:
>
> Warning: Explicit solution could not be found.
> > In solve at 98
- - - - - - - - - -
  This looks like a good problem for matlab's 'fzero'.

Roger Stafford

Subject: matlab solve function

From: Walter Roberson

Date: 2 Oct, 2010 04:17:04

Message: 4 of 6

On 01/10/10 8:20 PM, Anthony Hopf wrote:
> I am trying to find the scan angles of an expanding beam as the scan
> angle increases, but I don't want any overlap from beam realization to
> beam realization. The beamwidth is a function of the scan angle. I was
> hoping to use the matlab solve function no dice. My next thought is to
> do this numerically, but I need to do it a bunch of time.
>
> here is the code:
> npa = 1.3;
>
> bwaz = 2;
>
> az1 = 0;
>
> gamma = az1+(bwaz*cosd(az1)^npa)/2;
>
> solve('az2 - (bwaz*cosd(az2)^npa)/2 - gamma = 0');
>
> solving for az2, the next scan angle.

Poking around with this, it appears that there is no rational solution
for it.

You can, however, obtain a good approximation for it that you could then
pump into root finder. What you do is a series or taylor expansion on
the equation you are attempting to solve, out to order 5; dropping the
order term would leave you with a quartic, which you could then find the
first real root of. That real root will not be an exact solution, but it
will be right to several digits, which would give you a fair start to
the best solution.

You can do the series expansion of the symbolic expression without
giving a value to any of the variables that will change per iteration,
and thereafter evaluate the resulting expression at the current variable
values.

Mind you as this will be the root of a quartic, it will not be an
especially simple expression...

Subject: matlab solve function

From: Steven_Lord

Date: 4 Oct, 2010 14:49:42

Message: 5 of 6



"Anthony Hopf" <anthony.hopf@gmail.com> wrote in message
news:i861ct$spd$1@fred.mathworks.com...
> I am trying to find the scan angles of an expanding beam as the scan angle
> increases, but I don't want any overlap from beam realization to beam
> realization. The beamwidth is a function of the scan angle. I was hoping
> to use the matlab solve function no dice. My next thought is to do this
> numerically, but I need to do it a bunch of time.
>
> here is the code:
> npa = 1.3;
>
> bwaz = 2;
>
> az1 = 0;
>
> gamma = az1+(bwaz*cosd(az1)^npa)/2;
>
> solve('az2 - (bwaz*cosd(az2)^npa)/2 - gamma = 0');

Don't write your expression as a string; SOLVE can't use the values that you
defined above if you pass the expression into SOLVE as a string. Instead,
use:

syms az2
S = solve(az2 - (bwaz*cos(pi*az2/180)^npa)/2 - gamma, az2);

[Note that COSD is not defined for symbolic variables, so I replaced
cosd(az2) with cos(pi*az2/180).]

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: matlab solve function

From: Walter Roberson

Date: 4 Oct, 2010 14:56:04

Message: 6 of 6

On 04/10/10 9:49 AM, Steven_Lord wrote:
>
>
> "Anthony Hopf" <anthony.hopf@gmail.com> wrote in message

>> solve('az2 - (bwaz*cosd(az2)^npa)/2 - gamma = 0');

> Don't write your expression as a string; SOLVE can't use the values that
> you defined above if you pass the expression into SOLVE as a string.
> Instead, use:
>
> syms az2
> S = solve(az2 - (bwaz*cos(pi*az2/180)^npa)/2 - gamma, az2);

Good point in general.

In this particular case, there is no analytic expression for the
solution, so solve() will attempt to find numerical solutions. When I
was looking in to this particular expression, I found [experimentally]
that there were generally two real numeric solutions (at least to within
machine precision), and it was not clear that the lowest positive value
would always be the desired solution.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us