How can I choose powers of each variable separately and get it's value?
이전 댓글 표시
Hi every one I solved a equation leading to function like this f=x^a*y^b*z^c; but I don't know a,b and c.I want matlab to show me these power constants but have trouble making matlab select them. How can I choose powers of each variable separately and get it's value?
댓글 수: 3
Mahdi
2014년 5월 23일
Are you trying to fit data?
Azzi Abdelmalek
2014년 5월 23일
Can you explain what how did you get f? is f symbolic class?
답변 (2개)
Matt J
2014년 5월 23일
If there is no error in the equations, you can take logs and turn it into a linear equation in a,b, and c
logf=a*logx+b*logy+c*logz
댓글 수: 1
You can also use the linearization to develop an initial guess for the fminsearch approach (See Star Strider's answer).
Star Strider
2014년 5월 23일
You can do a nonlinear fit with fminsearch:
f = @(p,x,y,z) x.^p(1) .* y.^p(2) .* z.^p(3); % Function
x = 3; % Define variables
y = 5;
z = 7;
s = 13; % Define f(x,y,z,) = s
objfcn = @(p) f(p,x,y,z) - s; % Objective function = 0 when f(x,y,z,) = s
[b, fval] = fminsearch(objfcn, [1 1 1])
produces:
b =
11.3000 -3.0500 -25.5000
fval =
-13.0000
댓글 수: 4
Matt J
2014년 5월 23일
Should probably be
objfcn = @(p) norm( f(p,x,y,z) - s );
Star Strider
2014년 5월 23일
I don’t see why.
As far as we know, it’s a single-valued function. If we have a value for it for a given (x,y,z), we can accurately estimate the parameters as I described. If we don’t have these minimum conditions, it’s impossible to estimate the parameters.
If it’s part of a least-squares curve-fitting problem, a different (sum-of-squares) objective function is necessary. (The norm might be appropriate there, but since it involves the extra step of calculating the square root, usually isn’t used.)
If you don't include the norm(), your error function is signed. fminsearch will then look for the 'p' that makes the error function as negative as possible.
As an example, consider the alternative data x=13,y=1,z=1, s=13. With
objfcn = @(p) f(p,x,y,z) - s;
I obtain the false solution,
b =
-18.8889 6.2222 5.4278
fval =
-13
whereas when the norm() is included, fminsearch correctly detects that the initial point [1 1 1] is a solution,
b =
1 1 1
fval =
0
Star Strider
2014년 5월 23일
Noted. I’ve only done minimisation or least-squares curve fitting with fminsearch, so never encountered that.
카테고리
도움말 센터 및 File Exchange에서 Support Vector Machine Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!