is there something similar to Excel Solver in Matlab?

조회 수: 3 (최근 30일)
Andrew
Andrew 2011년 8월 10일
댓글: John C L Mayson II 2018년 5월 2일
Hi, I have a similar problem. To simplify assume a linear equation y=mx+c. I have values for the independent variable x, the actual y and want to solve for coefficients m and c. Using Excel Solver I would use random initial values for m and c in my equation, and get a fitted y, say y_fit. Then work the sum of squared residuals between y and y_fit [RSS = sum((y-yfit)^2)]. Then tell Solver to give me a solution for m and c which minimises RSS. Is this possible in Matlab? Can I make use of the Optimisation tool box to do this?

채택된 답변

Titus Edelhofer
Titus Edelhofer 2011년 8월 10일
Hi,
take a look at lsqcurvefit http://www.mathworks.com/help/toolbox/optim/ug/lsqcurvefit.html from Optimization Toolbox. It should do what you are looking for ...
Titus
  댓글 수: 2
Andrew
Andrew 2011년 8월 12일
Thanks Titus. That's what I was looking for. It worked:)
Andrew
John C L Mayson II
John C L Mayson II 2018년 5월 2일
Hi Andrew, I am a beginner in MATLAB and currently struggling with the same problem. I visited the link uploaded by Titus but still couldn't figure it out. I have a set of equations which obtains a variable "b". In one of those equations, I assumed a constant value for a variable "a". Now I want to set variable "b" to 0.01 by changing variable "a". Can you please help if you have the time?

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

추가 답변 (1개)

Fangjun Jiang
Fangjun Jiang 2011년 8월 10일
From help robustfit.
x = (1:10)';
y = 10 - 2*x + randn(10,1); y(10) = 0;
bls = regress(y,[ones(10,1) x])
brob = robustfit(x,y)
scatter(x,y)
hold on
plot(x,brob(1)+brob(2)*x,'r-', x,bls(1)+bls(2)*x,'m:')
  댓글 수: 2
Andrew
Andrew 2011년 8월 10일
Thanks Fangjun. Problem is that I want to apply solution to a wider problem that may not necessarily be minimising sum of squared residuals of a linear equation. So in this case, is it possible to minimise RSS by changing m and c by means of some iterative process?
Thanks once again.
Fangjun Jiang
Fangjun Jiang 2011년 8월 10일
I am not following. If you assume y=m*x+c, it means linear and the result from regress() is the result of minimizing RSS. If you want to do for example, y=n*x^2+m*x+c, then you can use regress(y,[ones(10,1) x x.^2]). There is no need to do iteration.

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

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by