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:
Matlab problem regarding to handle large number

Subject: Matlab problem regarding to handle large number

From: sk maidul haque

Date: 23 Dec, 2010 12:34:06

Message: 1 of 4

I am presently stuck at the following problem in matlab. Kindly reply me if you have any solution.

Matlab considers any number larger than 10^308 as inf.
In my program, within a for loop, a function like cos(x) or sin(x) is appearing where x is a complex No. and which leads sin(x) and cos (x) to be infinity(i.e. greater than 10^308).
I am not able to rescale the function sin(x) or cos(x) so that within the loop, I have to deal with small number and outside the loop I can multiply with the proper scaling factor to get the correct result.
To make the problem more explicit, I am giving some command lines of the program....


CM=[1 0
    0 1]; % initialize characteristic matrix by unit matrix
for j=1:l_n
    delta=(2*pi*(n{j}(l)-i*k{j}(l))*d{j})/l; % delta turns out to be some complex number
    eta=(n{j}(l)-i*k{j}(l)); % eta turns out to be some complex number
    M=[cos(delta) (i*sin(delta))/eta
       i*eta*sin(delta) cos(delta)];
   CM=M*CM;
end
BC=CM*[1 eta_m]';
B=BC(1);
C=BC(2);
T=(4*eta_0*eta_m)/[abs(eta_0*B+C)]^2;

Here, although T is a very small number which is intended to be calculated finally, I am to deal with a very large number cos(delta) and sin (delta) in the intermediate stage.
Please let me know, how to get rid of it.

Subject: Matlab problem regarding to handle large number

From: Walter Roberson

Date: 23 Dec, 2010 16:45:58

Message: 2 of 4

On 23/12/10 6:34 AM, sk maidul haque wrote:

> Matlab considers any number larger than 10^308 as inf.
> In my program, within a for loop, a function like cos(x) or sin(x) is
> appearing where x is a complex No. and which leads sin(x) and cos (x) to
> be infinity(i.e. greater than 10^308).

Chances are that if you have intermediate numbers that large, that the
result of your calculations are numeric nonsense, that you are
attempting to use information that requires more than 53 bits of
precision to be meaningful.

Unless you are able to reframe your calculations in log space, you will
have to switch to either the symbolic math toolkit, or the Matlab File
Exchange (FEX) contribution for dealing with variable precision numbers.
I do not know if that contribution supports sin() or cos().

Subject: Matlab problem regarding to handle large number

From: John D'Errico

Date: 23 Dec, 2010 18:45:23

Message: 3 of 4

Walter Roberson <roberson@hushmail.com> wrote in message <b1LQo.62819$wf4.33130@newsfe05.iad>...
> On 23/12/10 6:34 AM, sk maidul haque wrote:
>
> > Matlab considers any number larger than 10^308 as inf.
> > In my program, within a for loop, a function like cos(x) or sin(x) is
> > appearing where x is a complex No. and which leads sin(x) and cos (x) to
> > be infinity(i.e. greater than 10^308).
>
> Chances are that if you have intermediate numbers that large, that the
> result of your calculations are numeric nonsense, that you are
> attempting to use information that requires more than 53 bits of
> precision to be meaningful.
>
> Unless you are able to reframe your calculations in log space, you will
> have to switch to either the symbolic math toolkit, or the Matlab File
> Exchange (FEX) contribution for dealing with variable precision numbers.
> I do not know if that contribution supports sin() or cos().

One thing I have considered is to write a vpf tool. This
should be doable. It might be fun to compute sin(10^308)
out to a few hundred digits or so, and to do it accurately.

It is on the round tuit list.

John

Subject: Matlab problem regarding to handle large number

From: sk maidul haque

Date: 24 Dec, 2010 08:34:05

Message: 4 of 4

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <if05c3$bf9$1@fred.mathworks.com>...
> Walter Roberson <roberson@hushmail.com> wrote in message <b1LQo.62819$wf4.33130@newsfe05.iad>...
> > On 23/12/10 6:34 AM, sk maidul haque wrote:
> >
> > > Matlab considers any number larger than 10^308 as inf.
> > > In my program, within a for loop, a function like cos(x) or sin(x) is
> > > appearing where x is a complex No. and which leads sin(x) and cos (x) to
> > > be infinity(i.e. greater than 10^308).
> >
> > Chances are that if you have intermediate numbers that large, that the
> > result of your calculations are numeric nonsense, that you are
> > attempting to use information that requires more than 53 bits of
> > precision to be meaningful.
> >
> > Unless you are able to reframe your calculations in log space, you will
> > have to switch to either the symbolic math toolkit, or the Matlab File
> > Exchange (FEX) contribution for dealing with variable precision numbers.
> > I do not know if that contribution supports sin() or cos().
>
> One thing I have considered is to write a vpf tool. This
> should be doable. It might be fun to compute sin(10^308)
> out to a few hundred digits or so, and to do it accurately.
>
> It is on the round tuit list.
>
> John



Thank you very much Mr. John D'Errico for your reply.
I understand that reframing the calculation in log space or in any other scale to reduce the numbers in the intermediate stages would be the best solution of my problem. But, to my knowledge, it is quiet impossible since cos() and sin() which are numerically nonsense are all the elements of matrix and the matrix itself is within a for loop. If you know any trick to do the same please let me know.
 If not, then I have to necessarily switch to symbolic math toolkit. To that end, I would request you to kindly let me know how to use symbolic math toolkit in this context to handle large numbers. I should conface to you that I am pretty new to use matlab software. Please write me what does vpf tool mean......I could not follow this. Once again I want to remind you that the argument of sin function in my case is not that big but the argument is a complex number......and after operating this complex number with sin or cos fun leads to a value which is much greater than 10^308.
Thank you once again.

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