nlinfit not accurately modeling data

Hi! I am probably doing something stupid, but I have a bell-shaped function I want to model as an inverse of the sum of exponentials (of the form 1/(exp((x+a1)/a2)+exp((x+a3)/a4))+a5).
Here is what I have;
input=[-45:5:30]';
output=[.95;1.05;1.3;1.85;1.55;.95;.6;.5;.4;.35;.3;.275;.25;.225;.2;.175]';
mdl = @(a,x)((1/(exp((x+a(1))/a(2))+exp((x+a(3))/a(4))))+a(5))
a0=[97;-30;-18;15;.5];
and then
fitted=nlinfit(input, output, mdl, a0);
but the values I get back are terrible, and don't match the data at all, even when I change the starting values in a0. What am I doing wrong?

댓글 수: 3

the cyclist
the cyclist 2012년 1월 29일
I can't look at this right now, but try the following plots:
figure
hold on
plot(input,output,'b.-')
plot(input,mdl(a0,input),'r.-')
Is that about what you expect your initial guess to look like? I see you get a lot of warnings out of nlinfit, too, although I haven't looked at why.
Nick Schmandt
Nick Schmandt 2012년 1월 29일
The starting values I used were values from another bell-curve double exponential fit, but I must doing something wrong, because if I just type in mdl(a0, input), all the output values are zero except for the last one...
Nick Schmandt
Nick Schmandt 2012년 1월 29일
and thank you very much!

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

 채택된 답변

Tom Lane
Tom Lane 2012년 1월 29일

0 개 추천

In your model function you have "1/<stuff>" where you almost certainly intended element-by-element division, "1./<stuff>". You'll also want to remove the transpose from the definition of output.

댓글 수: 1

Nick Schmandt
Nick Schmandt 2012년 1월 31일
Thank you! That fixed it, the starting values were just off so much that it wasn't working.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by