Thread Subject: Fsolve

Subject: Fsolve

From: Sayanatn

Date: 30 Mar, 2011 18:09:20

Message: 1 of 8

Hi,

I am trying to run this program ..

Here i want to initialize the guess ,
then i want for different value of k the program automatically get the previous root as the initial for the next one

How can i do so

EXample:


function F = myyfun(x)


F = [2*x(1) -k* x(2) - exp(-x(1));
      -x(1) + 2*x(2) - exp(-x(2))];
(*The k is changing suppose from 1-10 with an increment of 1)

On another mfile i write

x0 = [-5; -5];

for k=1:1:10
[x] = fsolve(@myyfun, x0)
x0=[x]
end

Not working , what should i do?

Please help
(I want the first output of root to be the input for the guess for the second one)

Subject: Fsolve

From: John D'Errico

Date: 30 Mar, 2011 18:24:05

Message: 2 of 8

"Sayanatn " <sayan.polo@gmail.com> wrote in message <imvrkg$ift$1@fred.mathworks.com>...
> Hi,
>
> I am trying to run this program ..
>
> Here i want to initialize the guess ,
> then i want for different value of k the program automatically get the previous root as the initial for the next one
>
> How can i do so
>
> EXample:
>
>
> function F = myyfun(x)
>
>
> F = [2*x(1) -k* x(2) - exp(-x(1));
> -x(1) + 2*x(2) - exp(-x(2))];
> (*The k is changing suppose from 1-10 with an increment of 1)
>
> On another mfile i write
>
> x0 = [-5; -5];
>
> for k=1:1:10
> [x] = fsolve(@myyfun, x0)
> x0=[x]
> end
>
> Not working , what should i do?
>
> Please help
> (I want the first output of root to be the input for the guess for the second one)

What makes you think it is not working?

That will indeed use the previous value of x as the
start point x0.

Perhaps you are not updating k in your function?
You need to give us a better ACTUAL example of
non-working code for us to help you.

And then tell us what did not work!

John

Subject: Fsolve

From: Sayanatn

Date: 30 Mar, 2011 18:42:04

Message: 3 of 8

Hello ,

Thanks a lot for your response ,
First,
I am exactly using this program no details is missing

In one m file i am just writing the two simulataneous equations

as
function F = myyfun(x)


F = [2*x(1) -k* x(2) - exp(-x(1));
      -x(1) + 2*x(2) - exp(-x(2))];
Nothing else i am writting,now on a different m file i am just writting

x0 = [-5; -5];

for k=1:1:10
[x] = fsolve(@myyfun, x0)
x0=[x]
end

The error shown is this

??? Error using ==> feval
Error: File: myyfun.m Line: 3 Column: 19
Expression or statement is incomplete or incorrect.

Error in ==> fsolve at 254
            fuser = feval(funfcn{3},x,varargin{:});

Error in ==> myfunrun at 4
[x] = fsolve(@myyfun, x0)

Caused by:
    Failure in initial user-supplied objective function
    evaluation. FSOLVE cannot continue.
 I am new to this , and it might be stupid to ask , but help will be appreciated i wanna see how it works for this simple problem then can i implement to real problem,.

And i didnt get what you meant by i havent got the value of k ,I am using the for loop in the second m file for that , am i wrong ?

SD


"John D'Errico" <woodchips@rochester.rr.com> wrote in message <imvsg5$432$1@fred.mathworks.com>...
> "Sayanatn " <sayan.polo@gmail.com> wrote in message <imvrkg$ift$1@fred.mathworks.com>...
> > Hi,
> >
> > I am trying to run this program ..
> >
> > Here i want to initialize the guess ,
> > then i want for different value of k the program automatically get the previous root as the initial for the next one
> >
> > How can i do so
> >
> > EXample:
> >
> >
> > function F = myyfun(x)
> >
> >
> > F = [2*x(1) -k* x(2) - exp(-x(1));
> > -x(1) + 2*x(2) - exp(-x(2))];
> > (*The k is changing suppose from 1-10 with an increment of 1)
> >
> > On another mfile i write
> >
> > x0 = [-5; -5];
> >
> > for k=1:1:10
> > [x] = fsolve(@myyfun, x0)
> > x0=[x]
> > end
> >
> > Not working , what should i do?
> >
> > Please help
> > (I want the first output of root to be the input for the guess for the second one)
>
> What makes you think it is not working?
>
> That will indeed use the previous value of x as the
> start point x0.
>
> Perhaps you are not updating k in your function?
> You need to give us a better ACTUAL example of
> non-working code for us to help you.
>
> And then tell us what did not work!
>
> John

Subject: Fsolve

From: Steven_Lord

Date: 30 Mar, 2011 19:01:45

Message: 4 of 8



"Sayanatn " <sayan.polo@gmail.com> wrote in message
news:imvths$n33$1@fred.mathworks.com...
> Hello ,
>
> Thanks a lot for your response ,
> First,
> I am exactly using this program no details is missing
> In one m file i am just writing the two simulataneous equations
> as
> function F = myyfun(x)
>
>
> F = [2*x(1) -k* x(2) - exp(-x(1));
> -x(1) + 2*x(2) - exp(-x(2))];

Get rid of the extraneous spaces between your operations or wrap all the
operations that are supposed to be part of one term in parentheses.

F = [(2*x(1) -k* x(2) - exp(-x(1)));
     (-x(1) + 2*x(2) - exp(-x(2)))];

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Fsolve

From: Sayanatn

Date: 30 Mar, 2011 19:10:20

Message: 5 of 8

If i run as u said

the error shown is

?? Undefined function or variable 'k'.

Error in ==> myyfun at 7
F = [(2*x(1) -k* x(2) - exp(-x(1)));

Error in ==> fsolve at 254
            fuser = feval(funfcn{3},x,varargin{:});

Error in ==> myfunrun at 4
 [x] = fsolve(@myyfun, x0)

Caused by:
    Failure in initial user-supplied objective function
    evaluation. FSOLVE cannot continue.

I want all the roots for all the values of k only thing is the guess keeps on changing to the previous ones

Help


 "Steven_Lord" <slord@mathworks.com> wrote in message <imvul7$d8h$1@fred.mathworks.com>...
>
>
> "Sayanatn " <sayan.polo@gmail.com> wrote in message
> news:imvths$n33$1@fred.mathworks.com...
> > Hello ,
> >
> > Thanks a lot for your response ,
> > First,
> > I am exactly using this program no details is missing
> > In one m file i am just writing the two simulataneous equations
> > as
> > function F = myyfun(x)
> >
> >
> > F = [2*x(1) -k* x(2) - exp(-x(1));
> > -x(1) + 2*x(2) - exp(-x(2))];
>
> Get rid of the extraneous spaces between your operations or wrap all the
> operations that are supposed to be part of one term in parentheses.
>
> F = [(2*x(1) -k* x(2) - exp(-x(1)));
> (-x(1) + 2*x(2) - exp(-x(2)))];
>
> *snip*
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Fsolve

From: Sayanatn

Date: 30 Mar, 2011 23:05:04

Message: 6 of 8

??????



please help


"Sayanatn " <sayan.polo@gmail.com> wrote in message <imvrkg$ift$1@fred.mathworks.com>...
> Hi,
>
> I am trying to run this program ..
>
> Here i want to initialize the guess ,
> then i want for different value of k the program automatically get the previous root as the initial for the next one
>
> How can i do so
>
> EXample:
>
>
> function F = myyfun(x)
>
>
> F = [2*x(1) -k* x(2) - exp(-x(1));
> -x(1) + 2*x(2) - exp(-x(2))];
> (*The k is changing suppose from 1-10 with an increment of 1)
>
> On another mfile i write
>
> x0 = [-5; -5];
>
> for k=1:1:10
> [x] = fsolve(@myyfun, x0)
> x0=[x]
> end
>
> Not working , what should i do?
>
> Please help
> (I want the first output of root to be the input for the guess for the second one)

Subject: Fsolve

From: Alan Weiss

Date: 31 Mar, 2011 11:38:57

Message: 7 of 8

Take a look at the documentation on passing extra parameters:
http://www.mathworks.com/help/toolbox/optim/ug/brhkghv-7.html

Alan Weiss
MATLAB mathematical toolbox documentation

On 3/30/2011 3:10 PM, Sayanatn wrote:
> If i run as u said
> the error shown is
> ?? Undefined function or variable 'k'.
>
> Error in ==> myyfun at 7
> F = [(2*x(1) -k* x(2) - exp(-x(1)));
>
> Error in ==> fsolve at 254
> fuser = feval(funfcn{3},x,varargin{:});
>
> Error in ==> myfunrun at 4
> [x] = fsolve(@myyfun, x0)
>
> Caused by:
> Failure in initial user-supplied objective function
> evaluation. FSOLVE cannot continue.
>
> I want all the roots for all the values of k only thing is the guess
> keeps on changing to the previous ones
> Help
>
>
> "Steven_Lord" <slord@mathworks.com> wrote in message
> <imvul7$d8h$1@fred.mathworks.com>...
>>
>>
>> "Sayanatn " <sayan.polo@gmail.com> wrote in message
>> news:imvths$n33$1@fred.mathworks.com...
>> > Hello ,
>> >
>> > Thanks a lot for your response ,
>> > First,
>> > I am exactly using this program no details is missing
>> > In one m file i am just writing the two simulataneous equations
>> > as
>> > function F = myyfun(x)
>> >
>> >
>> > F = [2*x(1) -k* x(2) - exp(-x(1));
>> > -x(1) + 2*x(2) - exp(-x(2))];
>>
>> Get rid of the extraneous spaces between your operations or wrap all
>> the operations that are supposed to be part of one term in parentheses.
>>
>> F = [(2*x(1) -k* x(2) - exp(-x(1)));
>> (-x(1) + 2*x(2) - exp(-x(2)))];
>>
>> *snip*
>>
>> --
>> Steve Lord
>> slord@mathworks.com
>> To contact Technical Support use the Contact Us link on
>> http://www.mathworks.com

Subject: Fsolve

From: Steven_Lord

Date: 31 Mar, 2011 14:34:49

Message: 8 of 8



"Sayanatn " <sayan.polo@gmail.com> wrote in message
news:imvv6s$mqr$1@fred.mathworks.com...

*snip*

Please do not both post to the newsgroup AND email me directly; posting to
the newsgroup is sufficient.

See Alan's response earlier in this thread for the way to pass k into your
function.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Contact us at files@mathworks.com