From: Oluwa KuIse on
Hello,
I am working on a reactor problem and need to use nonlinear regression to find values of some coefficient so I wrote two files.
The first one is a function file of the model which is below:

function [Y]= pinpongbibi(X)
Y = X(:,3).*X(:,1).*X(:,2)./(X(:,1).*X(:,2)+X(:,4).*X(:,1).*(1+X(:,1)./X(:,6))+X(:,5).*X(:,2));

The second one is the script file to run it:

clear
close
clc

X = [0.15 0.15 0.15 0.15 0.15 0.15 0.33 0.33 0.33 0.33 0.33 0.33 0.33 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.72 0.72 0.72 0.72 0.72 0.72 0.72 0.93 0.93 0.93 0.93 0.93;
0.10 0.20 0.41 0.60 0.82 1.04 0.10 0.11 0.20 0.41 0.60 0.81 1.01 0.13 0.13 0.20 0.42 0.62 0.83 1.04 0.14 0.20 0.41 0.61 0.82 0.85 1.06 0.21 0.42 0.65 0.93 1.13;
0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10;
0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10;
0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10;
0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10]';
y = [1.19 1.74 1.92 1.97 2.06 2.09 0.90 1.00 1.29 1.63 1.88 1.94 1.97 0.80 0.79 1.03 1.45 1.61 1.74 1.89 0.73 0.90 1.27 1.51 1.56 1.69 1.75 0.70 1.16 1.37 1.51 1.70]';

BETA0 = pinpongbibi(X);

beta = nlinfit(X,y,@pinpongbibi,BETA0);


The command window gave me this error:

Error in ==> reactionrate at 15
beta = nlinfit(X,y,@pinpongbibi,BETA0);

Caused by:
Error using ==> pinpongbibi
Too many input arguments.

Does anyone know why I am getting this? I have tried to look through the documentation of nlinfit but I don't seem to understand the jargon used.
Thank you!
From: Yuri Geshelin on
"Oluwa KuIse" <wespeakforex(a)yahoo.com> wrote in message <hb4jsj$4er$1(a)fred.mathworks.com>...
> Hello,
> I am working on a reactor problem and need to use nonlinear regression to find values of some coefficient so I wrote two files.
> The first one is a function file of the model which is below:
>
> function [Y]= pinpongbibi(X)
> Y = X(:,3).*X(:,1).*X(:,2)./(X(:,1).*X(:,2)+X(:,4).*X(:,1).*(1+X(:,1)./X(:,6))+X(:,5).*X(:,2));
>
> The second one is the script file to run it:
>
> clear
> close
> clc
>
> X = [0.15 0.15 0.15 0.15 0.15 0.15 0.33 0.33 0.33 0.33 0.33 0.33 0.33 0.60 0.60 0.60 0.60 0.60 0.60 0.60 0.72 0.72 0.72 0.72 0.72 0.72 0.72 0.93 0.93 0.93 0.93 0.93;
> 0.10 0.20 0.41 0.60 0.82 1.04 0.10 0.11 0.20 0.41 0.60 0.81 1.01 0.13 0.13 0.20 0.42 0.62 0.83 1.04 0.14 0.20 0.41 0.61 0.82 0.85 1.06 0.21 0.42 0.65 0.93 1.13;
> 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10;
> 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10;
> 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10;
> 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10 0.10]';
> y = [1.19 1.74 1.92 1.97 2.06 2.09 0.90 1.00 1.29 1.63 1.88 1.94 1.97 0.80 0.79 1.03 1.45 1.61 1.74 1.89 0.73 0.90 1.27 1.51 1.56 1.69 1.75 0.70 1.16 1.37 1.51 1.70]';
>
> BETA0 = pinpongbibi(X);
>
> beta = nlinfit(X,y,@pinpongbibi,BETA0);
>
>
> The command window gave me this error:
>
> Error in ==> reactionrate at 15
> beta = nlinfit(X,y,@pinpongbibi,BETA0);
>
> Caused by:
> Error using ==> pinpongbibi
> Too many input arguments.
>
> Does anyone know why I am getting this? I have tried to look through the documentation of nlinfit but I don't seem to understand the jargon used.
> Thank you!

You have defined pinpongbibi as a function with only argument. It needs two. This is explained in the comments to NLINFIT (example):

% beta = nlinfit(reactants,rate,@mymodel,beta);
%
% where MYMODEL is a MATLAB function such as:
% function yhat = mymodel(beta, x)
From: Peter Perkins on
Oluwa KuIse wrote:

> function [Y]= pinpongbibi(X)
> Y = X(:,3).*X(:,1).*X(:,2)./(X(:,1).*X(:,2)+X(:,4).*X(:,1).*(1+X(:,1)./X(:,6))+X(:,5).*X(:,2));

> The command window gave me this error:
>
> Error in ==> reactionrate at 15
> beta = nlinfit(X,y,@pinpongbibi,BETA0);
>
> Caused by:
> Error using ==> pinpongbibi
> Too many input arguments.
>
> Does anyone know why I am getting this? I have tried to look through the documentation of nlinfit but I don't seem to understand the jargon used.

Here's the relevant part:

>> help nlinfit
NLINFIT Nonlinear least-squares regression.
[snip]
MODELFUN is a
function, specified using @, that accepts two arguments, a coefficient
vector and the array X, and returns a vector of fitted Y values.

Your model function only accepts one argument. It is supposed to do a calculation involving coefficients and predictor variables. Yours seemingly doesn't involve coefficients at all. See also the example in the help:

Examples:

Use @ to specify MODELFUN:
load reaction;
beta = nlinfit(reactants,rate,@mymodel,beta);

where MYMODEL is a MATLAB function such as:
function yhat = mymodel(beta, x)
yhat = (beta(1)*x(:,2) - x(:,3)/beta(5)) ./ ...
(1+beta(2)*x(:,1)+beta(3)*x(:,2)+beta(4)*x(:,3));
 | 
Pages: 1
Prev: Photo stitching
Next: help debug my program.