필터 지우기
필터 지우기

undefined function or variable when definition set

조회 수: 1 (최근 30일)
Gavin Seddon
Gavin Seddon 2015년 9월 16일
답변: Gavin Seddon 2015년 9월 16일
hello
my work space looks
'f, minusF, p1, p2, p3, p4, p5, p6, p7, p8, p9, RMSD, Sim'
however when I issue the fminbnd command I see
x = fminbnd(minusF,0,1200)
Undefined function or variable 'p9'.
Error in @(x)p1*x^8+p2*x^7+p3*x^6+p4*x^5+p5*x^4+p6*x^3+p7*x^2+p8*x+p9
Error in @(x)-f(x)
Error in fminbnd (line 215)
x= xf; fx = funfcn(x,varargin{:});
is this error caused by the workspace ordering? If so will someone corrects me or provide a link to the required order in which commands must be entered into Matlab please.
Gavin.

채택된 답변

Gavin Seddon
Gavin Seddon 2015년 9월 16일
Thanks, this briefly answers my long question Walter.

추가 답변 (2개)

Jan
Jan 2015년 9월 16일
Has p9 been defined before creating minusF?
Please post the relevant part of the code.

Walter Roberson
Walter Roberson 2015년 9월 16일
You should never create a function handle that mentions something that has not already been defined. The exception is that when you define an anonymous function, in the part after the @() you can mention any variable name that appeared inside the @()
The order must be to define p1, p2, p3, p4, p5, p6, p7, p8, p9, and then you can use
f = @(x) p1.*x.^8 + p2.*x.^7 + p3.*x.^6 + p4.*x.^5 + p5.*x.^4 + p6.*x.^3 + p7.*x.^2 + p8.*x + p9;
and then you can use
minusF = @(x) -f(x)
and then you can pass minusF into fminbnd()

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by