필터 지우기
필터 지우기

Equivalent of Excel Solver, fminunc?

조회 수: 5 (최근 30일)
Orongo
Orongo 2018년 3월 26일
댓글: Orongo 2018년 3월 26일
I'm replicating a calculation done in Excel with Matlab. The spreadsheet used Solver to find the smallest difference between a given value and an estimated value from a known function. The function is y=a+b*exp(c*x) where parameters a, b and c are to be estimated, x is the age. The formula is applied for range of ages and the minimum is the square difference (y_given-y_estimated)^2.
I'm able to use the function fminunc for one age but struggle to have this to a range of ages. My program looks like this
param0 = [0,0.2,1.2];
fun=@(param)f_Makeham(param0,y_given);
[S2, fval]=fminunc(fun,param0);
function res = f_Makeham(param,y_given)
x=(77.5:1:100.5)';
res = a0+b0.*exp(c0.*x);
This obviously generates an error.
How can I change the program to consider the minimum difference for a range of ages, and estimate a, b and c for those ages?

답변 (1개)

Torsten
Torsten 2018년 3월 26일
function res=f_Makeham(param,y_given)
a0=param(1);
b0=param(2);
c0=param(3);
x=(77.5:1:100.5)';
res=sum((a0+b0*exp(c0*x)-y_given).^2);
  댓글 수: 5
Torsten
Torsten 2018년 3월 26일
Could you include a plot of y_given vs. x ?
Orongo
Orongo 2018년 3월 26일

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by