Undefined function error. How to correct ?

I am trying to use the expand function. As a simple example i am trying to execute the following code as an m-file.
x=(1-r).^2; y=expand(x);
But it gives the following error: -------- ?? Undefined function or variable 'r'.
Error in ==> test at 1 l=(1-r).^2; ----x----
How to correct this error ??

 채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 2일

0 개 추천

Start with
syms r
As expand() is part of the symbolic toolkit.

댓글 수: 2

Matt Fig
Matt Fig 2011년 3월 2일
Now that would clear things up a bit!
Pankaj Wagh
Pankaj Wagh 2021년 4월 13일
I am facing the same Undefined Error for the raylrnd function. Can you suggest any solution for that?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt Fig
Matt Fig 2011년 3월 2일

0 개 추천

It would seem you need to define r. Try putting a WHOS right before the line that errors (or put a break point above that line and query the same way):
whos
x=(1-r).^2;
y=expand(x);
If you don't see an r in the list, you don't have r defined in the scope of the code. This is not a problem of the EXPAND function, but of your not having defined r where the code you are trying to execute can see it.
.
.
.
And why does the error indicate the problem is a line that looks like this:
l=(1-r).^2
but you showed the code as:
x=(1-r).^2
And did you read the help for EXPAND? Does it work with only one input according to the help?

댓글 수: 7

Bhagat
Bhagat 2011년 3월 2일
Yes, I don't see it.
I want to expand(1-x)^6. How do I do it ?
Bhagat
Bhagat 2011년 3월 2일
Sorry my mistake. It is x=(1-r).^2 in the error.
How do I define r ?
Yes , I tried the help example.---
expand((i-2)*(i-4))---
in the command window.It gave the following error----
??? Undefined function or method 'expand' for input arguments of type 'double'.
-----------
Bhagat
Bhagat 2011년 3월 2일
I am very new to MATLAB. These might be very basic doubts, but I've just started.Will appreciate help.
Matt Fig
Matt Fig 2011년 3월 2일
You need to make sure the EXPAND function is in the current directory or on your search path.
Bhagat
Bhagat 2011년 3월 2일
x is a vector. The function (1-x) has to be expanded to the power of 6. As (1-x)^2 expands to x^2-2*x+1.
Matt Fig
Matt Fig 2011년 3월 2일
Look at Walter's suggestion:
syms x
expand((1-x)^2)
I bet there is help for the EXPAND function available by typing:
help expand
Bhagat
Bhagat 2011년 3월 2일
Yes, i got that.
I had searched expand for help. But it wasn't mentioned that it is a part of symbol toolkit. Thanx anyway

댓글을 달려면 로그인하십시오.

질문:

2011년 3월 2일

댓글:

2021년 4월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by