10 views (last 30 days)

Hi I am trying to fit the data and find the constant values. my code is...

[T]=xlsread('Matlab.xlsx','sheet2','C5:C2685')

[alpha]=xlsread('Matlab.xlsx','sheet2','I5:I2685')%time

[dalpha_dt]=xlsread('Matlab.xlsx','sheet2','J5:J2685')

F=ones(size(alpha));

F=(1-alpha)

coeff0=[2.17E+22, 5] % initial guess

coeff=nlinfit([T,F],dalpha_dt,@model,coeff0);

A=coeff(:,1)

n=coeff(:,2)

Function:

function dhat=model(coef,a)

% par_fit = [a b]

a=coef(1);

b=coef(2);

T=a(:,1);

F=a(:,2);

% predicted model

dhat=a.*exp(208000./(8.3147*(T+273))).*(F^b);

return

I need to find the new coefficient values, but it is showing following error..Please tell me how to resolve this.

Error using nlinfit (line 205)

Error evaluating model function 'model'.

Error in fitting (line 16)

coeff=nlinfit([T,F],dalpha_dt,@model,coeff0);

Caused by:

Attempted to access a(:,2); index out of bounds because numel(a)=1.

Thanks

Star Strider
on 9 Oct 2015

You defined ‘a’ as a scalar (appropriately) so it is by definition a (1x1) ‘array’ (taking liberties with the concept here). It doesn’t have a second dimension.

How do you want to define ‘T’ and ‘F’?

Star Strider
on 9 Oct 2015

My pleasure.

You need the Global Optimization Toolbox to use the ga function it has, but relatively uncomplicated genetic algorithms are not difficult to program, especially in MATLAB.

Much has been written over the years about genetic algorithms. They are robust — if occasionally slow — problem solvers. The MATLAB documentation is very good (in my opinion). Since it recently changed, I encourage you to read the documentation for R2015a (that offered a different explanation and description of the essential knowledge underlying the various algorithms) as well as for R2015b (the current release).

Real world problems are frequently not easy to solve. You may also need a different model, or a revision of your current model. Since I do not know what you are doing (and I may not have the background to offer specific help even if I did), I cannot suggest any other approach.

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.