help-octave
[Top][All Lists]

## Numeric errors???

 From: Christophe TROESTLER Subject: Numeric errors??? Date: Thu, 17 Aug 2000 00:36:22 +0200 (CEST)

```Hi,

I am a beginner using Octave.  The two sets of functions below (H1,
H2, H3 and H11, H22, H33) should give the same result.  However, the
final results are dramatically different.  Anyone can help me with
this?  (Probably a stupid misunderstanding of mine.)

Thanks,
ChriS

-.¸¸.·´¯`·.¸¸.-.¸¸.·´¯`·.¸¸.-.¸¸.·´¯`·.¸¸.-.¸¸.·´¯`·.¸¸.-.¸¸.·´¯`·.¸¸.-

#!/usr/bin/octave -qf

global Id = eye(3,3)
global Y = zeros(3,3)
global X = [3, 0, 0;     0, 2, -1;     0, -2, 1]
global Z = [1, 1, 1;     1, 1, 1;     1, 1, 1]  # rank 1

function y = H1(a)
global Id; global X; global Y; global Z;
y = det( (a*Id - Y) + X * (a * Id - Z));
endfunction

function y = H2(a,b)
global Id; global X; global Y; global Z;
y = (a-b) * det( (a*Id-Y) * (b*Id-Y) + X * (a*Id-Z) * (b*Id-Z) );
endfunction

function y = H3(a,b,c)
y = H1(a) * H2(b,c) - H1(b) * H2(a,c) + H1(c) * H2(a,b);
endfunction

#rank(X * Z - Y * X) # = 1
H3(2,30,400) # = 120

function y = H11(a)
y = -12 * a^2 + 16 * a^3;
endfunction
function y = H22(a,b)
y = (a-b) * (36 * a^2 * b^2 - 12 * a^3 * b^2 - 12*a^2*b^3 + 16*a^3*b^3);
endfunction
function y = H33(a,b,c)
y = H11(a) * H22(b,c) - H11(b) * H22(a,c) + H11(c) * H22(a,b);
endfunction

H33(2,30,400) # = 0

printf("H2(30,400) - H22(30,400) = %.20fÜn", H2(30,400) - H22(30,400));
printf("H1(2)H2(30,400) - H11(2)H22(30,400)= %fÜn",
H1(2) * H2(30,400) - H11(2) * H22(30,400) );

printf("H1(400) -  H11(400) = %.20fÜn",   H1(400) - H11(400));
printf("H1(400)H2(2,30) - H11(400)H22(2,30)= %fÜn",
H1(400) * H2(2,30) - H11(400) * H22(2,30) );

-----------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.che.wisc.edu/octave/octave.html
How to fund new projects:  http://www.che.wisc.edu/octave/funding.html
Subscription information:  http://www.che.wisc.edu/octave/archive.html
-----------------------------------------------------------------------

```

reply via email to