Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: index out of bound because numel(x) = 1
Replies: 9   Last Post: Feb 10, 2014 3:05 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
question on Lorenz equation

Posts: 159
Registered: 12/7/04
Re: index out of bound because numel(x) = 1
Posted: Feb 7, 2014 7:07 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

dpb <none@non.net> wrote in message <ld3kcb$6dv$1@speranza.aioe.org>...
> On 2/7/2014 2:50 PM, Prabodh wrote:
> > dpb <none@non.net> wrote in message <ld3ct3$f64$1@speranza.aioe.org>...
> ...
>

> >> Your function should be only
> >>
> >> function F = trial(x,xdata)
> >> F = x(1)*exp(x(2)*xdata);
> >>
> >> where x is the vector of coefficients of the function, _NOT_ to be
> >> confused with the x variable of the function (xdata).
> >>
> >> Save this in the m-file 'trial.m' on the path (appears that's ok,
> >> altho you have some other stuff in the file that shouldn't be I'm
> >> guessing).
> >>
> >> Then as you did, define xdata, ydata and the starting guesses for the
> >> coefficients, x as x0 and call and all should be well.
> >>
> >> [x,resnorm] = lsqcurvefit(@trial,x0,xdata,ydata);
> >>
> >> NB that the only place x actually shows up is in the return vector
> >> output from lsqcurvefit. It is defined in length by the length(X0)
> >> internally and those initial guesses get modified automagically and
> >> returned in x(1) and x(2), respectively behind the scenes.
> >>
> >> I still do not understand. I have written exactly as you have told: -

> > function F = trial(x,xdata)
> > F = x(1)*exp(x(2)*xdata);
> > I deleted the line x =[1 0.2 3 4 5 6 7 8 9 10]; and put the other as it
> > was before: function F = trial(x,xdata)
> > F = x(1)*exp(x(2)*xdata);
> > xdata =[0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
> > ydata =[455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
> > x0 = [100; -1] [x,resnorm] = lsqcurvefit(@trial,x0,xdata,ydata);
> > Still the problem is not fixed. It gave the same error again. How do I
> > correct it? I have written this in the editor : - ctrl + shift + N (not
> > in the mupad). Is this the problem? Any suggestion will be helpful to me.
> > Thank you.

>
> lsqcurvefit has nothing to do w/ mupad and trial is an ordinary m-file,
> not a symbolic. I can't see your workspace but here there's no problem.
> Perhaps you should do a CLEAR of everything excepting the needed
> variables as well as the function in order to ensure you're using a
> latest copy.
>
> From the command line here (after creating trial.m, of course)...
>

> >> type trial.m
>
> function F = trial(x,xdata)
> F = x(1)*exp(x(2)*xdata);
>

> >> xdata =[0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
> ydata =[455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
> x0 = [100; -1];

> >> [x,resnorm] = lsqcurvefit(@trial,x0,xdata,ydata);
>
> Local minimum possible.
>
> lsqcurvefit stopped because the final change in the sum of squares
> relative to
> its initial value is less than the default value of the function tolerance.
>
> <stopping criteria details>
>

> >> x
> x =
> 498.8309
> -0.1013

> >> resnorm
> resnorm =
> 9.5049

> >>
>
> Seems to work as intended to estimate the coefficients.
>
> --

Thank you very much for your suggestion. I do not know what is happening in my Matlab. I am using version R 2013a student version. I wrote exactly what you have written starting from trial.m to [x,resnorm] = lsqcurvefit(@trial,x0,xdata,ydata); but still the problem is not fixed. It gave me the error message that: -

Error: File: trial.m Line: 2 Column: 1
Function definitions are not permitted in this context.
I do not know how I should correct it. Here is my complete code: -
trial.m
function F = trial(x,xdata)
F = x(1)*exp(x(2)*xdata);
xdata =[0.9 1.5 13.8 19.8 24.1 28.2 35.2 60.3 74.6 81.3];
ydata =[455.2 428.6 124.1 67.3 43.2 28.1 13.1 -0.4 -1.3 -1.5];
x0 = [100; -1];
[x,resnorm] = lsqcurvefit(@trial,x0,xdata,ydata);

Any suggestion would be highly helpful to me.
Thank you.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.