Got Questions? Get Answers.
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:
exceeds matrix dimensions,undefined function

Subject: exceeds matrix dimensions,undefined function

From: Snow White

Date: 20 Mar, 2009 19:45:05

Message: 1 of 11

Hello,

I want to find the value of n(x,y), I have the other values and following is the code that i have written, i can not mathematically filter out n(x,y):

numerator(x,y)=(((n(x,y))-(1/n(x,y)))^2)*((sin(theeta_incident))^2);
            denominator(x,y)=2+((2*(n(x,y)^2))-((n(x,y))+(1/n(x,y))^2))*((sin(theeta_incident))^2)+(4*(cos(theeta_incident)))*(sqrt((n(x,y)^2))-((sin(theeta_incident))^2));
            rho=numerator(x,y)/denominator(x,y);

For this i get the following error when i give some dummy value for n:

??? Index exceeds matrix dimensions.

Error in ==> refractive_index_estimation at 169
            numerator(x,y)=(((n(x,y))-(1/n(x,y)))^2)*((sin(theeta_incident))^2);

If i dont give the dummy value for n i get the following error:

??? Undefined function or method 'n' for input arguments of type 'double'.

Error in ==> refractive_index_estimation at 169
            numerator(x,y)=(((n(x,y))-(1/n(x,y)))^2)*((sin(theeta_incident))^2);


the things is my sole aim is to find the value of n can anyone help me with this?
 please its very urgent..

Bye

Subject: exceeds matrix dimensions,undefined function

From: Matt Fig

Date: 20 Mar, 2009 19:54:02

Message: 2 of 11

n better be an m-by-n matrix if you are requesting the element n(x,y). Both x and y also should be positive integers with x<=m and y<=n.

It seems as though you are thinking of n as a function of x and y. In that case you will have to define the function before calling it. See the help for anonymous functions.

Subject: exceeds matrix dimensions,undefined function

From: Snow White

Date: 20 Mar, 2009 20:12:01

Message: 3 of 11

it is an m by n matrix and both are positive integers. n is a number that is calculated at row x and column y position. So it is not a function

"Matt Fig" <spamanon@yahoo.com> wrote in message <gq0s8p$8if$1@fred.mathworks.com>...
> n better be an m-by-n matrix if you are requesting the element n(x,y). Both x and y also should be positive integers with x<=m and y<=n.
>
> It seems as though you are thinking of n as a function of x and y. In that case you will have to define the function before calling it. See the help for anonymous functions.

Subject: exceeds matrix dimensions,undefined function

From: someone

Date: 20 Mar, 2009 21:16:01

Message: 4 of 11

"Snow White" <gulesaman@gmail.com> wrote in message <gq0tah$lee$1@fred.mathworks.com>...
> it is an m by n matrix and both are positive integers. n is a number that is calculated at row x and column y position. So it is not a function
>
> "Matt Fig" <spamanon@yahoo.com> wrote in message <gq0s8p$8if$1@fred.mathworks.com>...
> > n better be an m-by-n matrix if you are requesting the element n(x,y). Both x and y also should be positive integers with x<=m and y<=n.
> >
> > It seems as though you are thinking of n as a function of x and y. In that case you will have to define the function before calling it. See the help for anonymous functions.

OK then, what is the size of n and what values of x and y are you using when you get the error message?

That should give you a hint.

Subject: exceeds matrix dimensions,undefined function

From: Steven Lord

Date: 20 Mar, 2009 21:26:53

Message: 5 of 11


"Snow White" <gulesaman@gmail.com> wrote in message
news:gq0ro1$3ah$1@fred.mathworks.com...
> Hello,
>
> I want to find the value of n(x,y), I have the other values and following
> is the code that i have written, i can not mathematically filter out
> n(x,y):
>
> numerator(x,y)=(((n(x,y))-(1/n(x,y)))^2)*((sin(theeta_incident))^2);
>
> denominator(x,y)=2+((2*(n(x,y)^2))-((n(x,y))+(1/n(x,y))^2))*((sin(theeta_incident))^2)+(4*(cos(theeta_incident)))*(sqrt((n(x,y)^2))-((sin(theeta_incident))^2));
> rho=numerator(x,y)/denominator(x,y);

Write a function that accepts a vector of M parameters, where M is the
number of elements you want your n matrix to contain, as well as whatever
other values it needs to calculate a value for numerator. Have your
function use those parameters to construct the matrix n and compute the
difference between the calculated value of numerator and the measured values
that you have for numerator. Then call FSOLVE to find M parameters that
make the difference the zero matrix.

--
Steve Lord
slord@mathworks.com

Subject: exceeds matrix dimensions,undefined function

From: Roger Stafford

Date: 20 Mar, 2009 21:31:01

Message: 6 of 11

"Snow White" <gulesaman@gmail.com> wrote in message <gq0ro1$3ah$1@fred.mathworks.com>...
> ......
> I want to find the value of n(x,y), I have the other values and following is the code that i have written, i can not mathematically filter out n(x,y):
>
> numerator(x,y)=(((n(x,y))-(1/n(x,y)))^2)*((sin(theeta_incident))^2);
> denominator(x,y)=2+((2*(n(x,y)^2))-((n(x,y))+(1/n(x,y))^2))*((sin(theeta_incident))^2)+(4*(cos(theeta_incident)))*(sqrt((n(x,y)^2))-((sin(theeta_incident))^2));
> rho=numerator(x,y)/denominator(x,y);
> ......

  When you say, "I have the other values", I presume you only mean that for each x and y you know the values of 'theeta_incident' and 'rho'. If you also know 'numerator(x,y)' and 'denominator(x,y)', the problem would be overdetermined with two equations and only one unknown. With that understood, it is possible with the appropriate algebraic manipulation to express 'n(x,y)' as one of the four roots of a quartic equation, for which there is a known formula, or alternatively it can be obtained using matlab's 'roots' function. For the latter method you would have to make a separate call on 'roots' for each pair x and y.

  At one point in an expression you have the square root of the square of n(x,y). In the general complex plane a square root can be either one of two possibilities. In obtaining the quartic it is necessary to know which of these to choose. Otherwise, both possibilities have to be explored, producing two different quartics, and giving rise to as many as eight different possible roots.

  You will be faced with the problem of selecting the appropriate root from among all the four (or eight) possibilities. We cannot advise you on that. Only you can decide which is to be the preferred one.

  My advice to you in doing the necessary algebra would be to abbreviate symbols such as 't' for 'theeta_incident' and 'n' for 'n(x,y)'. It saves a lot of "hen-scratching" and reduces the chances for errors. Also remove some of those numerous superfluous parentheses in your expressions. You are using many more than you need.

  An alternative to all the above is to use the 'solve' function in the Symbolic Toolbox to find expressions for the roots. However, be warned that it sometimes issues forth very cyptic answers.

Roger Stafford

Subject: exceeds matrix dimensions,undefined function

From: Snow White

Date: 20 Mar, 2009 23:14:06

Message: 7 of 11

I dont quite get your point. n(x,y) is one value that is determined at an image pixel location of x,y and so are the other values determined for that pixel location. I know rho and theeta_incident i have to find n(x,y).

"Steven Lord" <slord@mathworks.com> wrote in message <gq11me$kfv$1@fred.mathworks.com>...
>
> "Snow White" <gulesaman@gmail.com> wrote in message
> news:gq0ro1$3ah$1@fred.mathworks.com...
> > Hello,
> >
> > I want to find the value of n(x,y), I have the other values and following
> > is the code that i have written, i can not mathematically filter out
> > n(x,y):
> >
> > numerator(x,y)=(((n(x,y))-(1/n(x,y)))^2)*((sin(theeta_incident))^2);
> >
> > denominator(x,y)=2+((2*(n(x,y)^2))-((n(x,y))+(1/n(x,y))^2))*((sin(theeta_incident))^2)+(4*(cos(theeta_incident)))*(sqrt((n(x,y)^2))-((sin(theeta_incident))^2));
> > rho=numerator(x,y)/denominator(x,y);
>
> Write a function that accepts a vector of M parameters, where M is the
> number of elements you want your n matrix to contain, as well as whatever
> other values it needs to calculate a value for numerator. Have your
> function use those parameters to construct the matrix n and compute the
> difference between the calculated value of numerator and the measured values
> that you have for numerator. Then call FSOLVE to find M parameters that
> make the difference the zero matrix.
>
> --
> Steve Lord
> slord@mathworks.com
>

Subject: exceeds matrix dimensions,undefined function

From: Snow White

Date: 20 Mar, 2009 23:21:01

Message: 8 of 11

yes i know rho and theeta_incident... yes i can choose the appropriate value but the thing is how do i get those values... I am using the paranthesis to make it easy for myself.. so u r suggesting that i use ''roots'' and then ''solve''?
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gq11ul$8pe$1@fred.mathworks.com>...
> "Snow White" <gulesaman@gmail.com> wrote in message <gq0ro1$3ah$1@fred.mathworks.com>...
> > ......
> > I want to find the value of n(x,y), I have the other values and following is the code that i have written, i can not mathematically filter out n(x,y):
> >
> > numerator(x,y)=(((n(x,y))-(1/n(x,y)))^2)*((sin(theeta_incident))^2);
> > denominator(x,y)=2+((2*(n(x,y)^2))-((n(x,y))+(1/n(x,y))^2))*((sin(theeta_incident))^2)+(4*(cos(theeta_incident)))*(sqrt((n(x,y)^2))-((sin(theeta_incident))^2));
> > rho=numerator(x,y)/denominator(x,y);
> > ......
>
> When you say, "I have the other values", I presume you only mean that for each x and y you know the values of 'theeta_incident' and 'rho'. If you also know 'numerator(x,y)' and 'denominator(x,y)', the problem would be overdetermined with two equations and only one unknown. With that understood, it is possible with the appropriate algebraic manipulation to express 'n(x,y)' as one of the four roots of a quartic equation, for which there is a known formula, or alternatively it can be obtained using matlab's 'roots' function. For the latter method you would have to make a separate call on 'roots' for each pair x and y.
>
> At one point in an expression you have the square root of the square of n(x,y). In the general complex plane a square root can be either one of two possibilities. In obtaining the quartic it is necessary to know which of these to choose. Otherwise, both possibilities have to be explored, producing two different quartics, and giving rise to as many as eight different possible roots.
>
> You will be faced with the problem of selecting the appropriate root from among all the four (or eight) possibilities. We cannot advise you on that. Only you can decide which is to be the preferred one.
>
> My advice to you in doing the necessary algebra would be to abbreviate symbols such as 't' for 'theeta_incident' and 'n' for 'n(x,y)'. It saves a lot of "hen-scratching" and reduces the chances for errors. Also remove some of those numerous superfluous parentheses in your expressions. You are using many more than you need.
>
> An alternative to all the above is to use the 'solve' function in the Symbolic Toolbox to find expressions for the roots. However, be warned that it sometimes issues forth very cyptic answers.
>
> Roger Stafford

Subject: exceeds matrix dimensions,undefined function

From: Roger Stafford

Date: 21 Mar, 2009 08:43:01

Message: 9 of 11

"Snow White" <gulesaman@gmail.com> wrote in message <gq18ct$5nd$1@fred.mathworks.com>...
> ..... how do i get those values......
> ..... so u r suggesting that i use ''roots'' and then ''solve''?

  No, I am saying either 1) use good old-fashioned algebra with pen and paper to work out what the quartic is and solve it explicitly using the known standard methods for solving quartic equations, or 2) still use algebra to obtain the quartic and then 'roots' to get its roots. OR (not AND) 3) use 'solve' on the original equations to (hopefully) solve them. That is how you "get those values."

Roger Stafford

Subject: exceeds matrix dimensions,undefined function

From: Snow White

Date: 21 Mar, 2009 13:38:02

Message: 10 of 11

I have tried solving it mathematically and i can not solve it. ofcourse using pen and paper. So if this can not be factored out you mean to say it can not be solved?:S

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gq29al$mhb$1@fred.mathworks.com>...
> "Snow White" <gulesaman@gmail.com> wrote in message <gq18ct$5nd$1@fred.mathworks.com>...
> > ..... how do i get those values......
> > ..... so u r suggesting that i use ''roots'' and then ''solve''?
>
> No, I am saying either 1) use good old-fashioned algebra with pen and paper to work out what the quartic is and solve it explicitly using the known standard methods for solving quartic equations, or 2) still use algebra to obtain the quartic and then 'roots' to get its roots. OR (not AND) 3) use 'solve' on the original equations to (hopefully) solve them. That is how you "get those values."
>
> Roger Stafford

Subject: exceeds matrix dimensions,undefined function

From: Roger Stafford

Date: 22 Mar, 2009 01:08:01

Message: 11 of 11

"Snow White" <gulesaman@gmail.com> wrote in message <gq2qjq$bsi$1@fred.mathworks.com>...
> I have tried solving it mathematically and i can not solve it. ofcourse using pen and paper. So if this can not be factored out you mean to say it can not be solved?:S

  My conscience got the better of me and I decided to work out those quartic coefficients for you, Gule. I confess I avoided pen and paper by using the Symbolic Toolbox to aid in the messy algebra manipulation.

  As you recall I mentioned that the expression sqrt((n(x,y)^2)) can be interpreted in two ways, either as +n(x,y) or as -n(x,y), and each way gives rise to a different quartic equation. The five coefficients for the quartic in the +n(x,y) case are:

 A = (1-2*rho)*sin(t)^2
 B = rho*(sin(t)^2-4*cos(t))
 C = 2*(rho*(2*cos(t)*sin(t)^2-1)-sin(t)^2)
 D = 0
 E = (1+rho)*sin(t)^2

with the quartic equation being:

 A*n^4 + B*n^3 + C*n^2 + D*n + E = 0

where t = theeta_incident and n = n(x,y). In the -n(x,y) case all these coefficients remain the same except for the B coefficient which then changes to:

 B = rho*(sin(t)^2+4*cos(t))

  You can verify that these two sets of coefficients are correct by choosing various random values for t and rho and finding the eight possible roots for the two quartics using 'roots'. You can then check to see that all eight satisfy the original equations, remembering of course that sqrt((n(x,y)^2)) is to be interpreted as +n(x,y) or -n(x,y) according to which set of four roots is being tested.

Roger Stafford

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