Thread Subject: Fixed point Iteration (multivariable) 2

Subject: Fixed point Iteration (multivariable) 2

From: Sean Douglas

Date: 2 Jul, 2009 17:15:21

Message: 1 of 3

Hello I am trying to perform fixed point iteration on this problem:
 x1=g1(x1,x2)=(x1^2+x2^2+8)/10, x2=g2(x1,x2)=(x1*x2^2+x1+8)/10
 
first I made it one variable since I am x1 and x2 will be equal to each other anyways. Here is my mfile:
%Computes approximate solution of g(x)=x
%Input: inline function g, starting guess x0,
% number of steps k
%Output: Approximate solution xc
function xc=fpi(g,x0,k)
x(1)=x0;
for i=1:k
  x(i+1)=g(x(i));
end
x' %transpose output to a column
xc=x(k+1);

then I defined x and did the inline function:
>> clear
>> x=-10:.001:10;
>> x=fpi(inline('((x.^2+x.^2+8)/10)'),.5,2)

ans =

    0.5000
    0.8500
    0.9445


x =

0.9445 this worked nicely


Now I am trying to do this how the question was set up (with mulivariables). I changed my mfile and tried to do it. Here is what I have been up to:
First here is my new modified mfile:
%Attempting to set up multivariable Fixed-Point Iteration
%Computes approximate solution of g(x)=x
%Input: inline function g, starting guess x0,
% number of steps k
%Output: Approximate solution xc
function xc=fpi(g,x0,y0,k)
x(1)=(x0,y0);
for i=1:k
  x(i+1)=g(x(i),y(i));
end
x' %transpose output to a column
xc=x(k+1);

… and here is me calling the function and the MATLAB response
>> clear
x=-10:.001:10;
y=-10:.001:10;
>> x=fpixy(inline('((x.^2+y.^2+8)/10)'),.5,.5,2)
??? Error: File: fpixy.m Line: 7 Column: 9
Expression or statement is incorrect--possibly unbalanced (, {, or [.

I am pretty sure that it is not unbalaced, but something must be wrong with line 7 of my mfile, which is: x(1)=(x0,y0);

Can I even do a multivariable FPI?
I hope I described my situation clearly. Thanks for any help.

Subject: Fixed point Iteration (multivariable) 2

From: Steve Conahan

Date: 2 Jul, 2009 19:58:53

Message: 2 of 3

Hi Sean,

> ??? Error: File: fpixy.m Line: 7 Column: 9

As indicated, Line: 7 needs some re-writing:

  x(1)=(x0,y0);

I am not exactly sure what you are trying to do, but I suspect that the
right hand side of the above equation is not written correctly...perhaps you
need square braces [ instead of parentheses ( on the right hand side...

hth,
Steve


"Sean Douglas" <seanjdouglas@hotmail.com> wrote in message
news:h2ipv9$h8m$1@fred.mathworks.com...
> Hello I am trying to perform fixed point iteration on this problem:
> x1=g1(x1,x2)=(x1^2+x2^2+8)/10, x2=g2(x1,x2)=(x1*x2^2+x1+8)/10
>
> first I made it one variable since I am x1 and x2 will be equal to each
> other anyways. Here is my mfile:
> %Computes approximate solution of g(x)=x
> %Input: inline function g, starting guess x0,
> % number of steps k
> %Output: Approximate solution xc
> function xc=fpi(g,x0,k)
> x(1)=x0;
> for i=1:k
> x(i+1)=g(x(i));
> end
> x' %transpose output to a column
> xc=x(k+1);
>
> then I defined x and did the inline function:
>>> clear
>>> x=-10:.001:10;
>>> x=fpi(inline('((x.^2+x.^2+8)/10)'),.5,2)
>
> ans =
>
> 0.5000
> 0.8500
> 0.9445
>
>
> x =
>
> 0.9445 this worked nicely
>
>
> Now I am trying to do this how the question was set up (with
> mulivariables). I changed my mfile and tried to do it. Here is what I have
> been up to:
> First here is my new modified mfile:
> %Attempting to set up multivariable Fixed-Point Iteration
> %Computes approximate solution of g(x)=x
> %Input: inline function g, starting guess x0,
> % number of steps k
> %Output: Approximate solution xc
> function xc=fpi(g,x0,y0,k)
> x(1)=(x0,y0);
> for i=1:k
> x(i+1)=g(x(i),y(i));
> end
> x' %transpose output to a column
> xc=x(k+1);
>
> … and here is me calling the function and the MATLAB response
>>> clear
> x=-10:.001:10;
> y=-10:.001:10;
>>> x=fpixy(inline('((x.^2+y.^2+8)/10)'),.5,.5,2)
> ??? Error: File: fpixy.m Line: 7 Column: 9
> Expression or statement is incorrect--possibly unbalanced (, {, or [.
>
> I am pretty sure that it is not unbalaced, but something must be wrong
> with line 7 of my mfile, which is: x(1)=(x0,y0);
>
> Can I even do a multivariable FPI?
> I hope I described my situation clearly. Thanks for any help.

Subject: Fixed point Iteration (multivariable) 2

From: Sean Douglas

Date: 2 Jul, 2009 20:37:01

Message: 3 of 3

Thank you very much for response - just giving me new ideas helps alot.

square brackets[] will turn it into a matrix, I dont know if I want that even though the output get transposed at the end of the mfile.

BTW I did not need to use square brackets when I did the single variable problem that i put as an example in my previous question.
I dont know yet though, you may be on to something

thanks Steve



"Steve Conahan" <sconahan@mathworks.com> wrote in message <h2j3hu$mq4$1@fred.mathworks.com>...
> Hi Sean,
>
> > ??? Error: File: fpixy.m Line: 7 Column: 9
>
> As indicated, Line: 7 needs some re-writing:
>
> x(1)=(x0,y0);
>
> I am not exactly sure what you are trying to do, but I suspect that the
> right hand side of the above equation is not written correctly...perhaps you
> need square braces [ instead of parentheses ( on the right hand side...
>
> hth,
> Steve
>
>
> "Sean Douglas" <seanjdouglas@hotmail.com> wrote in message
> news:h2ipv9$h8m$1@fred.mathworks.com...
> > Hello I am trying to perform fixed point iteration on this problem:
> > x1=g1(x1,x2)=(x1^2+x2^2+8)/10, x2=g2(x1,x2)=(x1*x2^2+x1+8)/10
> >
> > first I made it one variable since I am x1 and x2 will be equal to each
> > other anyways. Here is my mfile:
> > %Computes approximate solution of g(x)=x
> > %Input: inline function g, starting guess x0,
> > % number of steps k
> > %Output: Approximate solution xc
> > function xc=fpi(g,x0,k)
> > x(1)=x0;
> > for i=1:k
> > x(i+1)=g(x(i));
> > end
> > x' %transpose output to a column
> > xc=x(k+1);
> >
> > then I defined x and did the inline function:
> >>> clear
> >>> x=-10:.001:10;
> >>> x=fpi(inline('((x.^2+x.^2+8)/10)'),.5,2)
> >
> > ans =
> >
> > 0.5000
> > 0.8500
> > 0.9445
> >
> >
> > x =
> >
> > 0.9445 this worked nicely
> >
> >
> > Now I am trying to do this how the question was set up (with
> > mulivariables). I changed my mfile and tried to do it. Here is what I have
> > been up to:
> > First here is my new modified mfile:
> > %Attempting to set up multivariable Fixed-Point Iteration
> > %Computes approximate solution of g(x)=x
> > %Input: inline function g, starting guess x0,
> > % number of steps k
> > %Output: Approximate solution xc
> > function xc=fpi(g,x0,y0,k)
> > x(1)=(x0,y0);
> > for i=1:k
> > x(i+1)=g(x(i),y(i));
> > end
> > x' %transpose output to a column
> > xc=x(k+1);
> >
> > … and here is me calling the function and the MATLAB response
> >>> clear
> > x=-10:.001:10;
> > y=-10:.001:10;
> >>> x=fpixy(inline('((x.^2+y.^2+8)/10)'),.5,.5,2)
> > ??? Error: File: fpixy.m Line: 7 Column: 9
> > Expression or statement is incorrect--possibly unbalanced (, {, or [.
> >
> > I am pretty sure that it is not unbalaced, but something must be wrong
> > with line 7 of my mfile, which is: x(1)=(x0,y0);
> >
> > Can I even do a multivariable FPI?
> > I hope I described my situation clearly. Thanks for any help.
>

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
fixed point ite... Sean Douglas 2 Jul, 2009 13:19:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com