Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
using homotopy continuation equation to solve one equation with one unknown

Subject: using homotopy continuation equation to solve one equation with one unknown

From: jieqiong liu

Date: 21 Oct, 2010 09:36:04

Message: 1 of 5

I always encounter an error message for the code i have constructed below,

fstring = [{'x/(1-x)-5*log10(0.4*(1-x)/(0.4-0.5*x))+4.45977'}];
varlist = [{'x'}];
%%%%%%%%%% Step 2: Make some choices for your problem:
%%% choose the initial values for your variable
initialval = [0];
%%% choose the limits for your solutions
aboxa = [-100,100] ;
%%% choose an upper value for s (in the ode system)
upS =1;
%%% choose the number of intermediate checks for [0, upperS]
checks = 70;
%%% choose an homotopy : FP or N
homoto = 'FP';
%homoto = 'N';
%%% choose an ODE solver
% odesol = 'ode15'; %% it actually the ode15s solver
odesol = 'ode45';
%%%%%%%%%%%%%%% Step 3: call the homotopy function
[hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto, odesol)
%%%%%%%%%%%%%%% Step 4: refine the solution calling fsolve
if ff == 1
nsol=fsolve(inline('[x/(1-x(1))-5*log10(0.4*(1-x(1))/(0.4-0.5*x(1)))+4.45977]','x'),hsol)
end

the error message is in this way:

??? Error using ==> inlineeval at 15
Error in inline expression ==> [5*log10((0.4*y(1) - 0.4)/(0.5*y(1) - 0.4)) +
y(1) + y(1)/(y(1) - 1) - 4.45977 ; - y(2) + y(2)*(y(1)/(y(1) - 1)^2 +
5*D(log10)((0.4*y(1) - 0.4)/(0.5*y(1) - 0.4))*((0.5*(0.4*y(1) -
0.4))/(0.5*y(1) - 0.4)^2 - 0.4/(0.5*y(1) - 0.4)) - 1/(y(1) - 1)) + 1]
 Error: ()-indexing must appear last in an index expression.

Error in ==> inline.feval at 36
        INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr,
        INLINE_OBJ_.expr);

Error in ==> odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...

Error in ==> htopy at 199
[timepoints, varvalues] = ode45(f,[checkpoints(j),checkpoints(j+1)],x0);

Error in ==> example1 at 24
[hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto,
odesol)


The hotopy.m file is provided...so I think the only problem lies with the equation I need to solve. Does anyone can help me out this?

Subject: using homotopy continuation equation to solve one equation with one unknown

From: Roger Stafford

Date: 21 Oct, 2010 17:24:04

Message: 2 of 5

"jieqiong liu" <liujq326@hotmail.com> wrote in message <i9p1i4$rqb$1@fred.mathworks.com>...
> I always encounter an error message for the code i have constructed below,
>
> fstring = [{'x/(1-x)-5*log10(0.4*(1-x)/(0.4-0.5*x))+4.45977'}];
> varlist = [{'x'}];
> %%%%%%%%%% Step 2: Make some choices for your problem:
> %%% choose the initial values for your variable
> initialval = [0];
> %%% choose the limits for your solutions
> aboxa = [-100,100] ;
> %%% choose an upper value for s (in the ode system)
> upS =1;
> %%% choose the number of intermediate checks for [0, upperS]
> checks = 70;
> %%% choose an homotopy : FP or N
> homoto = 'FP';
> %homoto = 'N';
> %%% choose an ODE solver
> % odesol = 'ode15'; %% it actually the ode15s solver
> odesol = 'ode45';
> %%%%%%%%%%%%%%% Step 3: call the homotopy function
> [hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto, odesol)
> %%%%%%%%%%%%%%% Step 4: refine the solution calling fsolve
> if ff == 1
> nsol=fsolve(inline('[x/(1-x(1))-5*log10(0.4*(1-x(1))/(0.4-0.5*x(1)))+4.45977]','x'),hsol)
> end
>
> the error message is in this way:
>
> ??? Error using ==> inlineeval at 15
> Error in inline expression ==> [5*log10((0.4*y(1) - 0.4)/(0.5*y(1) - 0.4)) +
> y(1) + y(1)/(y(1) - 1) - 4.45977 ; - y(2) + y(2)*(y(1)/(y(1) - 1)^2 +
> 5*D(log10)((0.4*y(1) - 0.4)/(0.5*y(1) - 0.4))*((0.5*(0.4*y(1) -
> 0.4))/(0.5*y(1) - 0.4)^2 - 0.4/(0.5*y(1) - 0.4)) - 1/(y(1) - 1)) + 1]
> Error: ()-indexing must appear last in an index expression.
>
> Error in ==> inline.feval at 36
> INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr,
> INLINE_OBJ_.expr);
>
> Error in ==> odearguments at 110
> f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
>
> Error in ==> ode45 at 173
> [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
>
> Error in ==> htopy at 199
> [timepoints, varvalues] = ode45(f,[checkpoints(j),checkpoints(j+1)],x0);
>
> Error in ==> example1 at 24
> [hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto,
> odesol)
>
>
> The hotopy.m file is provided...so I think the only problem lies with the equation I need to solve. Does anyone can help me out this?
- - - - - - - - - -
  I think the problem is with your 'inline' expression used within the 'fsolve' call. You have put indices in all but the first occurrence of the 'x' variable: x(1). I don't think 'inline' will operate properly with that. Why haven't you written this:

 inline('x/(1-x)-5*log10(0.4*(1-x)/(0.4-0.5*x))+4.45977','x') ?

  Out of curiosity, is the htopy.m file you used the same one as shown in the article by Decarolis, Mayer, and Santamaria entitled "Homotopy Continuation Methods"? I don't see it listed on any of Mathworks' websites.

Roger Stafford

Subject: using homotopy continuation equation to solve one equation with one unknown

From: jieqiong liu

Date: 22 Oct, 2010 03:05:04

Message: 3 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i9psvk$sq0$1@fred.mathworks.com>...
> "jieqiong liu" <liujq326@hotmail.com> wrote in message <i9p1i4$rqb$1@fred.mathworks.com>...
> > I always encounter an error message for the code i have constructed below,
> >
> > fstring = [{'x/(1-x)-5*log10(0.4*(1-x)/(0.4-0.5*x))+4.45977'}];
> > varlist = [{'x'}];
> > %%%%%%%%%% Step 2: Make some choices for your problem:
> > %%% choose the initial values for your variable
> > initialval = [0];
> > %%% choose the limits for your solutions
> > aboxa = [-100,100] ;
> > %%% choose an upper value for s (in the ode system)
> > upS =1;
> > %%% choose the number of intermediate checks for [0, upperS]
> > checks = 70;
> > %%% choose an homotopy : FP or N
> > homoto = 'FP';
> > %homoto = 'N';
> > %%% choose an ODE solver
> > % odesol = 'ode15'; %% it actually the ode15s solver
> > odesol = 'ode45';
> > %%%%%%%%%%%%%%% Step 3: call the homotopy function
> > [hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto, odesol)
> > %%%%%%%%%%%%%%% Step 4: refine the solution calling fsolve
> > if ff == 1
> > nsol=fsolve(inline('[x/(1-x(1))-5*log10(0.4*(1-x(1))/(0.4-0.5*x(1)))+4.45977]','x'),hsol)
> > end
> >
> > the error message is in this way:
> >
> > ??? Error using ==> inlineeval at 15
> > Error in inline expression ==> [5*log10((0.4*y(1) - 0.4)/(0.5*y(1) - 0.4)) +
> > y(1) + y(1)/(y(1) - 1) - 4.45977 ; - y(2) + y(2)*(y(1)/(y(1) - 1)^2 +
> > 5*D(log10)((0.4*y(1) - 0.4)/(0.5*y(1) - 0.4))*((0.5*(0.4*y(1) -
> > 0.4))/(0.5*y(1) - 0.4)^2 - 0.4/(0.5*y(1) - 0.4)) - 1/(y(1) - 1)) + 1]
> > Error: ()-indexing must appear last in an index expression.
> >
> > Error in ==> inline.feval at 36
> > INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr,
> > INLINE_OBJ_.expr);
> >
> > Error in ==> odearguments at 110
> > f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
> >
> > Error in ==> ode45 at 173
> > [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
> >
> > Error in ==> htopy at 199
> > [timepoints, varvalues] = ode45(f,[checkpoints(j),checkpoints(j+1)],x0);
> >
> > Error in ==> example1 at 24
> > [hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto,
> > odesol)
> >
> >
> > The hotopy.m file is provided...so I think the only problem lies with the equation I need to solve. Does anyone can help me out this?
> - - - - - - - - - -
> I think the problem is with your 'inline' expression used within the 'fsolve' call. You have put indices in all but the first occurrence of the 'x' variable: x(1). I don't think 'inline' will operate properly with that. Why haven't you written this:
>
> inline('x/(1-x)-5*log10(0.4*(1-x)/(0.4-0.5*x))+4.45977','x') ?
>
> Out of curiosity, is the htopy.m file you used the same one as shown in the article by Decarolis, Mayer, and Santamaria entitled "Homotopy Continuation Methods"? I don't see it listed on any of Mathworks' websites.
>
> Roger Stafford


Dear Roger,

Really appreciated your help. Yes, I use the same file as the article shown. The hotopy.m file it explained are suitable to solve equation with one unknown. So do I need to make any adjustment on the hotopy.m file?

Regards,
Jie

Subject: using homotopy continuation equation to solve one equation with one unknown

From: jieqiong liu

Date: 22 Oct, 2010 05:58:04

Message: 4 of 5

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i9psvk$sq0$1@fred.mathworks.com>...
> "jieqiong liu" <liujq326@hotmail.com> wrote in message <i9p1i4$rqb$1@fred.mathworks.com>...
> > I always encounter an error message for the code i have constructed below,
> >
> > fstring = [{'x/(1-x)-5*log10(0.4*(1-x)/(0.4-0.5*x))+4.45977'}];
> > varlist = [{'x'}];
> > %%%%%%%%%% Step 2: Make some choices for your problem:
> > %%% choose the initial values for your variable
> > initialval = [0];
> > %%% choose the limits for your solutions
> > aboxa = [-100,100] ;
> > %%% choose an upper value for s (in the ode system)
> > upS =1;
> > %%% choose the number of intermediate checks for [0, upperS]
> > checks = 70;
> > %%% choose an homotopy : FP or N
> > homoto = 'FP';
> > %homoto = 'N';
> > %%% choose an ODE solver
> > % odesol = 'ode15'; %% it actually the ode15s solver
> > odesol = 'ode45';
> > %%%%%%%%%%%%%%% Step 3: call the homotopy function
> > [hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto, odesol)
> > %%%%%%%%%%%%%%% Step 4: refine the solution calling fsolve
> > if ff == 1
> > nsol=fsolve(inline('[x/(1-x(1))-5*log10(0.4*(1-x(1))/(0.4-0.5*x(1)))+4.45977]','x'),hsol)
> > end
> >
> > the error message is in this way:
> >
> > ??? Error using ==> inlineeval at 15
> > Error in inline expression ==> [5*log10((0.4*y(1) - 0.4)/(0.5*y(1) - 0.4)) +
> > y(1) + y(1)/(y(1) - 1) - 4.45977 ; - y(2) + y(2)*(y(1)/(y(1) - 1)^2 +
> > 5*D(log10)((0.4*y(1) - 0.4)/(0.5*y(1) - 0.4))*((0.5*(0.4*y(1) -
> > 0.4))/(0.5*y(1) - 0.4)^2 - 0.4/(0.5*y(1) - 0.4)) - 1/(y(1) - 1)) + 1]
> > Error: ()-indexing must appear last in an index expression.
> >
> > Error in ==> inline.feval at 36
> > INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr,
> > INLINE_OBJ_.expr);
> >
> > Error in ==> odearguments at 110
> > f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
> >
> > Error in ==> ode45 at 173
> > [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
> >
> > Error in ==> htopy at 199
> > [timepoints, varvalues] = ode45(f,[checkpoints(j),checkpoints(j+1)],x0);
> >
> > Error in ==> example1 at 24
> > [hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto,
> > odesol)
> >
> >
> > The hotopy.m file is provided...so I think the only problem lies with the equation I need to solve. Does anyone can help me out this?
> - - - - - - - - - -
> I think the problem is with your 'inline' expression used within the 'fsolve' call. You have put indices in all but the first occurrence of the 'x' variable: x(1). I don't think 'inline' will operate properly with that. Why haven't you written this:
>
> inline('x/(1-x)-5*log10(0.4*(1-x)/(0.4-0.5*x))+4.45977','x') ?
>
> Out of curiosity, is the htopy.m file you used the same one as shown in the article by Decarolis, Mayer, and Santamaria entitled "Homotopy Continuation Methods"? I don't see it listed on any of Mathworks' websites.
>
> Roger Stafford


Dear Roger,

After I have modified to inline(). there are error message displayed as below,

??? Error using ==> sym.sym>expression2ref at 2408
Error: ')' expected [line 1, col 48]

Error in ==> sym.sym>char2ref at 2378
    s = expression2ref(x);

Error in ==> sym.sym>tomupad at 2147
        S = char2ref(x);

Error in ==> sym.sym>sym.sym at 102
                S.s = tomupad(x,'');

Error in ==> htopy at 92
allfun = [allfun, sym(fu{i})];

Error in ==> example1 at 24
[hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto,
odesol);


May I know where is the problem?
Appreciated your attention.

regards,
Jie

Subject: using homotopy continuation equation to solve one equation with one unknown

From: Roger Stafford

Date: 22 Oct, 2010 07:41:03

Message: 5 of 5

"jieqiong liu" <liujq326@hotmail.com> wrote in message <i9r95c$1er$1@fred.mathworks.com>...
> Dear Roger,
>
> After I have modified to inline(). there are error message displayed as below,
>
> ??? Error using ==> sym.sym>expression2ref at 2408
> Error: ')' expected [line 1, col 48]
>
> Error in ==> sym.sym>char2ref at 2378
> s = expression2ref(x);
>
> Error in ==> sym.sym>tomupad at 2147
> S = char2ref(x);
>
> Error in ==> sym.sym>sym.sym at 102
> S.s = tomupad(x,'');
>
> Error in ==> htopy at 92
> allfun = [allfun, sym(fu{i})];
>
> Error in ==> example1 at 24
> [hsol, ff] = htopy(fstring,varlist,initialval, upS,checks, aboxa, homoto,
> odesol);
>
> May I know where is the problem?
- - - - - - - - - -
  I am not familiar with the 'htopy' algorithm, though it seems like an interesting concept. However, fortunately your error appears to be very near the beginning where the cell array 'allfun' is being set up. You have only one function, so the result should be a cell array with a single element in it, namely your expression with an acquired symbolic status. This is something you could try separately. Find out what is wrong at the step

 allfun = [allfun,sym(fu{i})];

inside the for-loop there. There may be something about the way you defined fstring that it is objecting to. Try executing this directly:

fstring = [{'x/(1-x)-5*log10(0.4*(1-x)/(0.4-0.5*x))+4.45977'}];
allfun = sym([]);
allfun = [allfun,sym(fstring{1})];

and see if matlab complains.

  I am puzzled by the way you defined 'aboxa'. You set it at [-100,100], but the upper limit 100 is far beyond the range of valid values for x. You are starting with an initial value of x = 0, so you should never allow x to equal or exceed 0.8 if you are to avoid encountering infinities or negative quantities inside the log10 function.

Roger Stafford

Tags for this Thread

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.

Contact us