solve dimension mismatch

  • Follow


hello

i would like to solve the following nonlinear equation for x:

(1+(x*r./48)+(((x*r./48)).^2)./2)*(up_down(a)+1./up_down(a))-1-(1+(x*r./24)+(((x*r./24).^2)./2))-x*vol(b)^2

when i do this via the solve-function, i get the error "??? Subscripted assignment dimension mismatch.". what i don't understand is that when i use the function

exp((r/48)*x)*(up_down(a)+1/up_down(a))-1-exp((r/24)*x)-x*vol(b)^2

which is practically the same, i don't have any problems. is it because i am using too many x-variables in the first equation?

many thanks in advance for your help
0
Reply Thomas 12/17/2010 12:49:04 PM

On 17/12/10 6:49 AM, Thomas Erd=C3=B6si wrote:

> i would like to solve the following nonlinear equation for x:
>
> (1+(x*r./48)+(((x*r./48)).^2)./2)*(up_down(a)+1./up_down(a))-1-(1+(x*r.=
/24)+(((x*r./24).^2)./2))-x*vol(b)^2
>
>
> when i do this via the solve-function, i get the error "??? Subscripted=

> assignment dimension mismatch.". what i don't understand is that when i=

> use the function
>
> exp((r/48)*x)*(up_down(a)+1/up_down(a))-1-exp((r/24)*x)-x*vol(b)^2
>
> which is practically the same, i don't have any problems. is it because=

> i am using too many x-variables in the first equation?

We need the context in which the error occurs -- the exact line of code=20
that is flagged, and the traceback from there to the exact line of code=20
that you used.

Lacking better information, my suspicion would be that you are assigning =

the result of solve() to a subscripted variable, and that the problem is =

that solve() is finding a different number of solutions than you are=20
expecting... perhaps no solutions at all.

When I feed the formulae in to Maple, using symbolic coefficients, Maple =

finds two solutions for your first formula, and finds a single=20
incomplete solution for the second formula. When I put some random=20
values in for the constants in the second formula, it appears that there =

is only a single solution for it.

0
Reply Walter 12/17/2010 2:02:06 PM


Walter Roberson <roberson@hushmail.com> wrote in message <y3KOo.4473$ju1.3824@newsfe14.iad>...
> On 17/12/10 6:49 AM, Thomas Erdösi wrote:
> 
> > i would like to solve the following nonlinear equation for x:
> >
> > (1+(x*r./48)+(((x*r./48)).^2)./2)*(up_down(a)+1./up_down(a))-1-(1+(x*r./24)+(((x*r./24).^2)./2))-x*vol(b)^2
> >
> >
> > when i do this via the solve-function, i get the error "??? Subscripted
> > assignment dimension mismatch.". what i don't understand is that when i
> > use the function
> >
> > exp((r/48)*x)*(up_down(a)+1/up_down(a))-1-exp((r/24)*x)-x*vol(b)^2
> >
> > which is practically the same, i don't have any problems. is it because
> > i am using too many x-variables in the first equation?
> 
> We need the context in which the error occurs -- the exact line of code 
> that is flagged, and the traceback from there to the exact line of code 
> that you used.
> 
> Lacking better information, my suspicion would be that you are assigning 
> the result of solve() to a subscripted variable, and that the problem is 
> that solve() is finding a different number of solutions than you are 
> expecting... perhaps no solutions at all.
> 
> When I feed the formulae in to Maple, using symbolic coefficients, Maple 
> finds two solutions for your first formula, and finds a single 
> incomplete solution for the second formula. When I put some random 
> values in for the constants in the second formula, it appears that there 
> is only a single solution for it.

i see the problem now, the solve-function finds two solutions for the first equation. this doesn't work because i save the results to the equation for various different inputs in a preallocated matrix dti=zeros(m-1,m) and two solutions won't fit. i shall only need the second, positive result, the first (negative) result can be ignored.
is there a way for me to only use the positive of the two results and save it into the dti matrix?

my complete code is as follows:

r=0.015;
m=173

dti=zeros(m-1,m);
for a=1:(m-2)
syms x
vol=volatility(2:m,a);
for b=1:(m-a)
dti(b,a)=solve((1+(x*r/48)+(((x*r/48))^2)/2)*(up_down(a)+1/up_down(a))-1-(1+(x*r/24)+(((x*r/24)^2)/2))-x*vol(b)^2,x);
end
end
dti(1,m-1)=1;

thank you
0
Reply Thomas 12/17/2010 2:29:06 PM

On 17/12/10 8:29 AM, Thomas Erd=C3=B6si wrote:

> i see the problem now, the solve-function finds two solutions for the
> first equation. this doesn't work because i save the results to the
> equation for various different inputs in a preallocated matrix
> dti=3Dzeros(m-1,m) and two solutions won't fit. i shall only need the
> second, positive result, the first (negative) result can be ignored.
> is there a way for me to only use the positive of the two results and
> save it into the dti matrix?

t =3D vpa(solve(....));
dti(b,a) =3D t(t>=3D0);

0
Reply Walter 12/17/2010 2:52:54 PM

Walter Roberson <roberson@hushmail.com> wrote in message <aPKOo.14006$Qi5.13809@newsfe01.iad>...
> On 17/12/10 8:29 AM, Thomas Erdösi wrote:
> 
> > i see the problem now, the solve-function finds two solutions for the
> > first equation. this doesn't work because i save the results to the
> > equation for various different inputs in a preallocated matrix
> > dti=zeros(m-1,m) and two solutions won't fit. i shall only need the
> > second, positive result, the first (negative) result can be ignored.
> > is there a way for me to only use the positive of the two results and
> > save it into the dti matrix?
> 
> t = vpa(solve(....));
> dti(b,a) = t(t>=0);

this is somehow not implemented in my regular student matlab version:

??? Error using ==> sym.sym>notimplemented at 2514
Function 'ge' is not implemented for MuPAD symbolic objects.

Error in ==> sym.sym>sym.ge at 814
            notimplemented('ge');

Error in ==> time_steps_w at 19

i get the same error when i do the following:

if t(1)<0
dti(b,a)=t(2)
else
dti(b,a)=t(1)
dti(b,a)=t(t>=0);

is there a way to work around this problem?
0
Reply Thomas 12/17/2010 4:02:20 PM

On 17/12/10 10:02 AM, Thomas Erd=C3=B6si wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message
> <aPKOo.14006$Qi5.13809@newsfe01.iad>...
>> On 17/12/10 8:29 AM, Thomas Erd=C3=B6si wrote:
>>
>> > i see the problem now, the solve-function finds two solutions for th=
e
>> > first equation. this doesn't work because i save the results to the
>> > equation for various different inputs in a preallocated matrix
>> > dti=3Dzeros(m-1,m) and two solutions won't fit. i shall only need th=
e
>> > second, positive result, the first (negative) result can be ignored.=

>> > is there a way for me to only use the positive of the two results an=
d
>> > save it into the dti matrix?
>>
>> t =3D vpa(solve(....));
>> dti(b,a) =3D t(t>=3D0);
>
> this is somehow not implemented in my regular student matlab version:
>
> ??? Error using =3D=3D> sym.sym>notimplemented at 2514
> Function 'ge' is not implemented for MuPAD symbolic objects.

That would happen for sure if you do not have the vpa() call.

If you *do* have the vpa() call and it is still happening, then the=20
implication is that the solutions you are getting back are inherently=20
symbolic, not convertible to pure floating point numbers. If that is the =

case, it makes no sense to talk about which is positive or negative=20
(though it might make sense to talk about a particular _part_ of the=20
symbolic expression being positive or negative.)

0
Reply Walter 12/17/2010 5:26:14 PM

Walter Roberson <roberson@hushmail.com> wrote in message <W2NOo.14034$Qi5.9849@newsfe01.iad>...
> On 17/12/10 10:02 AM, Thomas Erdösi wrote:
> > Walter Roberson <roberson@hushmail.com> wrote in message
> > <aPKOo.14006$Qi5.13809@newsfe01.iad>...
> >> On 17/12/10 8:29 AM, Thomas Erdösi wrote:
> >>
> >> > i see the problem now, the solve-function finds two solutions for the
> >> > first equation. this doesn't work because i save the results to the
> >> > equation for various different inputs in a preallocated matrix
> >> > dti=zeros(m-1,m) and two solutions won't fit. i shall only need the
> >> > second, positive result, the first (negative) result can be ignored.
> >> > is there a way for me to only use the positive of the two results and
> >> > save it into the dti matrix?
> >>
> >> t = vpa(solve(....));
> >> dti(b,a) = t(t>=0);
> >
> > this is somehow not implemented in my regular student matlab version:
> >
> > ??? Error using ==> sym.sym>notimplemented at 2514
> > Function 'ge' is not implemented for MuPAD symbolic objects.
> 
> That would happen for sure if you do not have the vpa() call.
> 
> If you *do* have the vpa() call and it is still happening, then the 
> implication is that the solutions you are getting back are inherently 
> symbolic, not convertible to pure floating point numbers. If that is the 
> case, it makes no sense to talk about which is positive or negative 
> (though it might make sense to talk about a particular _part_ of the 
> symbolic expression being positive or negative.)

i do have the vpa() call and it's still happening. it may be the case that the solve function solves the equation for x first 'symbolically' and then enters the numerical variables to find the final numerical value of x. however, for the second equation in my first comment above i would always get a numerical result, which is of course the ultimate goal. do you see a way to, if necessary, transform the symbolic results into numerical ones, and then check whether they are positive or negative?
many thanks again 
0
Reply Thomas 12/17/2010 7:17:08 PM

On 10-12-17 01:17 PM, Thomas Erd=C3=B6si wrote:

>> >> t =3D vpa(solve(....));
>> >> dti(b,a) =3D t(t>=3D0);
>> >
>> > this is somehow not implemented in my regular student matlab version=
:
>> >
>> > ??? Error using =3D=3D> sym.sym>notimplemented at 2514
>> > Function 'ge' is not implemented for MuPAD symbolic objects.

Please show us an example of what t contains after the solve() step.

0
Reply Walter 12/17/2010 7:21:59 PM

Walter Roberson <roberson@hushmail.com> wrote in message <iegd8p$pod$1@nrc-news.nrc.ca>...
> On 10-12-17 01:17 PM, Thomas Erdösi wrote:
> 
> >> >> t = vpa(solve(....));
> >> >> dti(b,a) = t(t>=0);
> >> >
> >> > this is somehow not implemented in my regular student matlab version:
> >> >
> >> > ??? Error using ==> sym.sym>notimplemented at 2514
> >> > Function 'ge' is not implemented for MuPAD symbolic objects.
> 
> Please show us an example of what t contains after the solve() step.

after substituting all variables (except for x) for example values, we should get a 2x1 matrix(?) containing the two possible solutions to the equation, e.g. (-4000,1)'.
0
Reply Thomas 12/17/2010 7:37:08 PM

On 10-12-17 01:37 PM, Thomas Erd=C3=B6si wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message
> <iegd8p$pod$1@nrc-news.nrc.ca>...
>> On 10-12-17 01:17 PM, Thomas Erd=C3=B6si wrote:
>>
>> >> >> t =3D vpa(solve(....));
>> >> >> dti(b,a) =3D t(t>=3D0);
>> >> >
>> >> > this is somehow not implemented in my regular student matlab vers=
ion:
>> >> >
>> >> > ??? Error using =3D=3D> sym.sym>notimplemented at 2514
>> >> > Function 'ge' is not implemented for MuPAD symbolic objects.
>>
>> Please show us an example of what t contains after the solve() step.
>
> after substituting all variables (except for x) for example values, we =
should
> get a 2x1 matrix(?) containing the two possible solutions to the equati=
on,
> e.g. (-4000,1)'.

*Should* may be different than what you actually get.

In the matlab editor, position your cursor on the '-' after the line numb=
er of=20
the line containing the assignment to dti(b,a) . Right click on that '-' =
and=20
choose Set Conditional Breakpoint. In the text box that comes up, type in=


~isnumeric(t)

and okay that. Now run the program. When the debugger stops the program, =

display a and b and t and class(t) and show us those values.

0
Reply Walter 12/17/2010 7:52:43 PM

Walter Roberson <roberson@hushmail.com> wrote in message <iegf2d$qt4$1@nrc-news.nrc.ca>...
> On 10-12-17 01:37 PM, Thomas Erdösi wrote:
> > Walter Roberson <roberson@hushmail.com> wrote in message
> > <iegd8p$pod$1@nrc-news.nrc.ca>...
> >> On 10-12-17 01:17 PM, Thomas Erdösi wrote:
> >>
> >> >> >> t = vpa(solve(....));
> >> >> >> dti(b,a) = t(t>=0);
> >> >> >
> >> >> > this is somehow not implemented in my regular student matlab version:
> >> >> >
> >> >> > ??? Error using ==> sym.sym>notimplemented at 2514
> >> >> > Function 'ge' is not implemented for MuPAD symbolic objects.
> >>
> >> Please show us an example of what t contains after the solve() step.
> >
> > after substituting all variables (except for x) for example values, we should
> > get a 2x1 matrix(?) containing the two possible solutions to the equation,
> > e.g. (-4000,1)'.
> 
> *Should* may be different than what you actually get.
> 
> In the matlab editor, position your cursor on the '-' after the line number of 
> the line containing the assignment to dti(b,a) . Right click on that '-' and 
> choose Set Conditional Breakpoint. In the text box that comes up, type in
> 
> ~isnumeric(t)
> 
> and okay that. Now run the program. When the debugger stops the program, 
> display a and b and t and class(t) and show us those values.

a=1
b=1
t=<2x1 sym>
x=<2x1 sym>
there's a small dice-shaped symbol behind the t and x.
0
Reply Thomas 12/17/2010 8:10:08 PM

correction, x=<1x1 sym>, very sorry.
0
Reply Thomas 12/17/2010 8:12:05 PM

On 10-12-17 02:10 PM, Thomas Erd=C3=B6si wrote:

> a=3D1
> b=3D1
> t=3D<2x1 sym>
> x=3D<2x1 sym>

Okay, that establishes that the result is definitely symbolic; now we nee=
d to=20
see the contents of t. You might have to display t(1) and t(2) separately=
=2E


0
Reply Walter 12/17/2010 8:41:00 PM

Walter Roberson <roberson@hushmail.com> wrote in message <ieghst$s73$2@nrc-news.nrc.ca>...
> On 10-12-17 02:10 PM, Thomas Erdösi wrote:
> 
> > a=1
> > b=1
> > t=<2x1 sym>
> > x=<2x1 sym>
> 
> Okay, that establishes that the result is definitely symbolic; now we need to 
> see the contents of t. You might have to display t(1) and t(2) separately.
> 

i left the conditional breakpoint at dti(b,a) and wrote
t1=t(1);
t2=t(2);
dti(b,a)=t(t>=0);

this gave me <1x1 sym> as a result for both t1 and t2. interestingly, when i drag the cursor over t1 or t2 in the editor it shows me their numerical results: t1=-4913, t2=1.88
0
Reply Thomas 12/17/2010 9:02:21 PM

On 10-12-17 03:02 PM, Thomas Erd=C3=B6si wrote:
> Walter Roberson <roberson@hushmail.com> wrote in message
> <ieghst$s73$2@nrc-news.nrc.ca>...
>> On 10-12-17 02:10 PM, Thomas Erd=C3=B6si wrote:
>>
>> > a=3D1
>> > b=3D1
>> > t=3D<2x1 sym>
>> > x=3D<2x1 sym>
>>
>> Okay, that establishes that the result is definitely symbolic; now we =
need
>> to see the contents of t. You might have to display t(1) and t(2) sepa=
rately.
>>
>
> i left the conditional breakpoint at dti(b,a) and wrote
> t1=3Dt(1);
> t2=3Dt(2);
> dti(b,a)=3Dt(t>=3D0);
>
> this gave me <1x1 sym> as a result for both t1 and t2. interestingly, w=
hen i
> drag the cursor over t1 or t2 in the editor it shows me their numerical=

> results: t1=3D-4913, t2=3D1.88

Duh! I got the wrong call! Instead of vpa() it should be double()

t =3D double(solve(....));
dti(b,a) =3D t(t>0);

0
Reply Walter 12/17/2010 9:09:36 PM

> 
> Duh! I got the wrong call! Instead of vpa() it should be double()
> 
> t = double(solve(....));
> dti(b,a) = t(t>0);

This is working perfectly now, thank you so much!! But i don't understand this, what exactly does the 'double(solve(...))' do?
0
Reply Thomas 12/17/2010 10:57:05 PM

15 Replies
177 Views

(page loaded in 0.192 seconds)

Similiar Articles:







7/17/2012 11:12:20 AM


Reply: