Discussion:
curve fitting with nlinfit
(too old to reply)
Anna Hayton
2010-07-27 06:39:02 UTC
Permalink
I am trying to use nlinfit to find four unknown parameters. I have used a similar method before but now when I run the code I get the following error message

??? Error using ==> nlinfit at 117
The model function 'myfun' was not found.

Error in ==> findf>qfit at 24
a = nlinfit(t,y,'myfun',a);

Error in ==> findf at 13
a = qfit(xdata,ydata);


This is my code -

function [a z] = findf(x,y)

%the raw data
energy = [15 20 25 30 40 60 80 100 662 2000 6000]';
depth = [NaN NaN 137.6855 143.9123 144.7387 129.8625 119.9215 122.6316 104.6974 100.1030 95.7069]';

a = qfit(energy,depth);

function [a z] = qfit(t,y)
a = [0.0115 -2.0 4000000 -70];
a = nlinfit(t,y,'myfun',a);
z = myfun(a,t);

function f = myfun(a,t)
f = 100*(1-exp(-a(1)*(t-a(2))))*(1 + (a(3)/((t-a(4))^3)));

Any help appreciated
Robert Cumming
2010-07-27 06:59:05 UTC
Permalink
Post by Anna Hayton
I am trying to use nlinfit to find four unknown parameters. I have used a similar method before but now when I run the code I get the following error message
??? Error using ==> nlinfit at 117
The model function 'myfun' was not found.
Error in ==> findf>qfit at 24
a = nlinfit(t,y,'myfun',a);
Error in ==> findf at 13
a = qfit(xdata,ydata);
This is my code -
function [a z] = findf(x,y)
%the raw data
energy = [15 20 25 30 40 60 80 100 662 2000 6000]';
depth = [NaN NaN 137.6855 143.9123 144.7387 129.8625 119.9215 122.6316 104.6974 100.1030 95.7069]';
a = qfit(energy,depth);
function [a z] = qfit(t,y)
a = [0.0115 -2.0 4000000 -70];
a = nlinfit(t,y,'myfun',a);
z = myfun(a,t);
function f = myfun(a,t)
f = 100*(1-exp(-a(1)*(t-a(2))))*(1 + (a(3)/((t-a(4))^3)));
Any help appreciated
Peter Perkins
2010-07-27 16:59:11 UTC
Permalink
Post by Anna Hayton
I am trying to use nlinfit to find four unknown parameters. I have
used a similar method before but now when I run the code I get the
following error message
??? Error using ==> nlinfit at 117
The model function 'myfun' was not found.
Error in ==> findf>qfit at 24
a = nlinfit(t,y,'myfun',a);
Error in ==> findf at 13
a = qfit(xdata,ydata);
You have quotes around the myfun which are an error, and it should have
It turns out that NLINFIT will also recognize a function name (NLINFIT
existed before function handles did). But in this case, the function
being named appears to be local to the file, so it's not on the path to
anyone outside that file, including NLINFIT. Robert's suggested fix is
the right one.

Also, the function is gonna need some dots in the times and power
operators, to make them elementwise:

function f = myfun(a,t)
f = 100*(1-exp(-a(1).*(t-a(2)))).*(1 + (a(3)./((t-a(4)).^3)));

ss3329
2010-07-27 07:03:46 UTC
Permalink
[url=http://www.b2bsharing.com/nike-shox-shoes-mens-shox-r4-torch-shoes-c-3502_3734_3743.html][b]Nike shox r4 [/b][/url] Men

’s shoe is the most famous product [url=http://www.b2bsharing.com/footwear-nike-shox-shoes-c-3502_3734.html], etc. [b]Nike

Shox running shoes[/b][/url] produced material is comfortable and airy. [url=http://www.b2bsharing.com/nike-shox-shoes-

mens-shox-r3-shoes-c-3502_3734_3739.html][b]Shox r3[/b][/url] has managed to invite the awareness of Disney, For demand. As

a part of the [url=http://www.b2bsharing.com/footwear-nike-shox-shoes-c-3502_3734.html][b]Nike Shox[/b][/url] family, this

stylish shoe is sure to be a hit amongst athletes and others looking for the latest in style and fashion. There are more and

more people to buy [url=http://www.b2bsharing.com/footwear-nike-shox-shoes-c-3502_3734.html][b]wholesale nike shox [/b][/url]

Nike shox r3 comes equipped with extra padding built into the heel for athletic purposes as well the [b]

[url=http://www.b2bsharing.com/nike-shox-shoes-womens-shox-turb-shoes-c-3502_3734_3750.html]Women's Shox Turb Shoes[/url]

[/b]is designed streamlined for style, comfort, as well as for practical reasons as arunning shoe or trainer.
Loading...