ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

error: Math script code giving only zeros..

I have this code . I know it works in MATLAB. I tried to make it work in MathScript but in the last step, i only get M to be a zero matrix. however it should have values then. What is wrong??

t = (0:0.0000001:.01);

f1 = .0011312*cos(2*pi*49400*t);

f2 = .0033936*cos(2*pi*100*t);

H = (f1 + f2);

x = ((2.93464*10^-10)*H);

ms=1000;

M = ms * (coth(x) - (1./x));

0 Kudos
Message 1 of 7
(4,361 Views)
I think someone suggested entering the code into the Mathscript Window line-by-line, so that you can see the progression of your variables. For a small script like this, it's a great way to  debug it.
Jarrod S.
National Instruments
0 Kudos
Message 2 of 7
(4,359 Views)
I have input the code one at a time. It shows values of all them except M. I get H, x, ms, everything except M.
0 Kudos
Message 3 of 7
(4,355 Views)
I tried your script in Matlab 6.5.1 and I essentially got zeros for M. It sort of makes sense. The array x is an array of exceedingly small numbers (on the order of 10E-12), which is effectively zero. The coth of 0 is undefined.
0 Kudos
Message 4 of 7
(4,341 Views)
On Dec 11, 11:40 am, Kris Matrix <x...@no.email> wrote:
> I have this code . I know it works in MATLAB. I tried to make it work in MathScript but in the last step, i only get M to be a zero matrix. however it should have values then. What is wrong??
> t = (0:0.0000001:.01);
> f1 = .0011312*cos(2*pi*49400*t);
> f2 = .0033936*cos(2*pi*100*t);
> H = (f1 + f2);
> x = ((2.93464*10^-10)*H);
> ms=1000;
> M = ms * (coth(x) - (1./x));

I wouldn't trust the answer in either Matlab or Labview. Wirh X being
approximately 1 x 10^-12 the coth of x and 1/x are both approximately
1 x 10^12 you are trying to calculate the difference between two very
large numbers. This is often an invitation to a disaster. I suggest
you rework your equations to eliminate the problem of determining the
difference between two large numbers.

Howard
0 Kudos
Message 5 of 7
(4,331 Views)
On Dec 11, 11:00 pm, hrh1818 <hr...@att.net> wrote:
> On Dec 11, 11:40 am, Kris Matrix <x...@no.email> wrote:
>
> > I have this code . I know it works in MATLAB. I tried to make it work in MathScript but in the last step, i only get M to be a zero matrix. however it should have values then. What is wrong??
> > t = (0:0.0000001:.01);
> > f1 = .0011312*cos(2*pi*49400*t);
> > f2 = .0033936*cos(2*pi*100*t);
> > H = (f1 + f2);
> > x = ((2.93464*10^-10)*H);
> > ms=1000;
> > M = ms * (coth(x) - (1./x));
>
> I wouldn't trust the answer in either Matlab or Labview. Wirh X being
> approximately 1 x 10^-12 the coth of x and 1/x are both approximately
> 1 x 10^12 you are trying to calculate the difference between two very
> large numbers. This is often an invitation to a disaster. I suggest
> you rework your equations to eliminate the problem of determining the
> difference between two large numbers.
>
> Howard


I took another look at your question this morning and noticed most of
the values Matlab gave for M were equal to zero. Then I visually
compared some values of x that produced an answer of zero for M and
those that gave a non-zero value. Here is the comparison for Matlab.

show = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
>> x(show)

ans =

1.0e-011 *

Columns 1 through 7

0.1328 0.1328 0.1327 0.1326 0.1325 0.1324 0.1322

Columns 8 through 10

0.1320 0.1318 0.1315

>> M(show)

ans =

Columns 1 through 7

0 0 0 0 0 0.1221 0

Columns 8 through 10

0 0 0.1221

Notice how close the x values that gave a zero result are to the x
values that gave a non-zero result. That doesn't make sense. Hence I
conclude your problem as presently defined isn't suitable for Matlab
or Labview.

Howard
0 Kudos
Message 6 of 7
(4,311 Views)
On Dec 11, 11:40 am, Kris Matrix <x...@no.email> wrote:
> I have this code . I know it works in MATLAB. I tried to make it work in MathScript but in the last step, i only get M to be a zero matrix. however it should have values then. What is wrong??
> t = (0:0.0000001:.01);
> f1 = .0011312*cos(2*pi*49400*t);
> f2 = .0033936*cos(2*pi*100*t);
> H = (f1 + f2);
> x = ((2.93464*10^-10)*H);
> ms=1000;
> M = ms * (coth(x) - (1./x));

Another update. I ran your code in Matlab using variable precision
arithmetic as follows.

>> digits(25)
>> y = vpa(x);
>> z = y([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
>> 1000 * (coth(z) - (1./z))

ans =

[ .5000e-9, .4000e-9, .4000e-9, .4000e-9, .4000e-9, .4000e-9, .
4000e-9, .4000e-9, .5000e-9, .5000e-9]

The answer given by variable precision arithmetic for the first ten x
values is completely different than the values given by double
precision arithmetic.

Howard
0 Kudos
Message 7 of 7
(4,290 Views)