From: Mohammad on
Dear reader,

I have a sinusoidal function, v(x), which should be odd, since sin is an odd function, and x is an odd function, so sin(...)-x should be odd.
However when you plot it


Star=[0.592606202481246,-0.238596363969608,0.110220888524900,-0.048828233710702,0.019375152829649,-0.006571603729450,0.001814612417602,-3.812550640549345e-04,5.414560164816563e-05,-3.901808006180736e-06];
v = @(x) sin(pi*x(:)*(1:r))*Star.'+a-x;
fplot(v,[n o])


it is not odd. Why?

Thanks!

Cordially, Mohammad
From: Walter Roberson on
Mohammad wrote:

> I have a sinusoidal function, v(x), which should be odd, since sin is an
> odd function, and x is an odd function, so sin(...)-x should be odd.
> However when you plot it
>
>
> Star=[0.592606202481246,-0.238596363969608,0.110220888524900,-0.048828233710702,0.019375152829649,-0.006571603729450,0.001814612417602,-3.812550640549345e-04,5.414560164816563e-05,-3.901808006180736e-06];
>
> v = @(x) sin(pi*x(:)*(1:r))*Star.'+a-x;
> fplot(v,[n o])
>
>
> it is not odd. Why?

Undefined variable n .
From: Mohammad on
z = 1;
n = -.5;
o = .5;
a = 0;
r = 10;
b = 1;
mat=zeros(r,r+1);
for i= 1:r
for j = 1:r
mat(i,j) = sin(j*pi*(o-(o-n)*(i-1)/2/r));%(o-(o-n)*(i-1)/2/r)=x
end
for j = 1+r
mat(i,j) = z*((o-(o-n)*(i-1)/2/r))^b;
end
end
for j=2:r,
for i=j:r,
mat(i,:) = mat(i,:) - mat(j-1,:)*mat(i,j-1)/mat(j-1,j-1);
end
end
Bat = rot90(mat,2);
Hat=[Bat Bat(:,1)];
Hat(:,1)=[];
for j=2:r,
for i=j:r,
Hat(i,:) = Hat(i,:) - Hat(j-1,:)*Hat(i,j-1)/Hat(j-1,j-1);
end
end
Fat = rot90(Hat,2);
Rat=[Fat Fat(:,1)];
Rat(:,1)=[];
Star=zeros(1,r);
for i = 1:r
Star(1,i)=Rat(i,end)/Rat(i,i);
end
v = @(x) sin(pi*x(:)*(1:r))*Star.'+a-x^b;
fplot(v,[n o])
fid = fopen('hope.txt', 'w');
number3 = a;
fprintf(fid,['A0 is ' num2str(number3)]);
for i = 1:r
number = Star(1,i);
number2 = i;
fprintf(fid,['\nA' num2str(number2) ' is ' num2str(number)]);
end
fclose(fid);
type hope.txt
From: Walter Roberson on
Mohammad wrote:

> v = @(x) sin(pi*x(:)*(1:r))*Star.'+a-x^b;

Good question, but in the above expression you need x.^b rather than x^b .

If x is already a column vector, then you do not need the (:) after x
and if x is a row vector then you need - (x.').^b to avoid mismatches on the
sizes. If x is a 2D matrix rather than a vector then you are going to get
mismatches on the sizes.

> fplot(v,[n o])

I manually plotted v(-0.5:.1:0.5) and it _does_ appear to be an odd vector
like you expect. For some reason, though, fplot does not plot the same values
and does not plot the right hand tail at all correctly -- at least not in 2008b.
From: Roger Stafford on
"Mohammad " <jaber2(a)uni.uiuc.edu> wrote in message <i3phfs$p51$1(a)fred.mathworks.com>...
> Dear reader,
>
> I have a sinusoidal function, v(x), which should be odd, since sin is an odd function, and x is an odd function, so sin(...)-x should be odd.
> However when you plot it
>
> Star=[0.592606202481246,-0.238596363969608,0.110220888524900,-0.048828233710702,0.019375152829649,-0.006571603729450,0.001814612417602,-3.812550640549345e-04,5.414560164816563e-05,-3.901808006180736e-06];
> v = @(x) sin(pi*x(:)*(1:r))*Star.'+a-x;
> fplot(v,[n o])
>
> it is not odd. Why?
> Thanks!
> Cordially, Mohammad

"Mohammad " <jaber2(a)uni.uiuc.edu> wrote in message <i3pj80$hea$1(a)fred.mathworks.com>...
> z = 1;
> n = -.5;
> o = .5;
> a = 0;
> r = 10;
> b = 1;
> mat=zeros(r,r+1);
> for i= 1:r
> for j = 1:r
> mat(i,j) = sin(j*pi*(o-(o-n)*(i-1)/2/r));%(o-(o-n)*(i-1)/2/r)=x
> end
> for j = 1+r
> mat(i,j) = z*((o-(o-n)*(i-1)/2/r))^b;
> end
> end
> for j=2:r,
> for i=j:r,
> mat(i,:) = mat(i,:) - mat(j-1,:)*mat(i,j-1)/mat(j-1,j-1);
> end
> end
> Bat = rot90(mat,2);
> Hat=[Bat Bat(:,1)];
> Hat(:,1)=[];
> for j=2:r,
> for i=j:r,
> Hat(i,:) = Hat(i,:) - Hat(j-1,:)*Hat(i,j-1)/Hat(j-1,j-1);
> end
> end
> Fat = rot90(Hat,2);
> Rat=[Fat Fat(:,1)];
> Rat(:,1)=[];
> Star=zeros(1,r);
> for i = 1:r
> Star(1,i)=Rat(i,end)/Rat(i,i);
> end
> v = @(x) sin(pi*x(:)*(1:r))*Star.'+a-x^b;
> fplot(v,[n o])
> fid = fopen('hope.txt', 'w');
> number3 = a;
> fprintf(fid,['A0 is ' num2str(number3)]);
> for i = 1:r
> number = Star(1,i);
> number2 = i;
> fprintf(fid,['\nA' num2str(number2) ' is ' num2str(number)]);
> end
> fclose(fid);
> type hope.txt
- - - - - - - - - -
Hello Mohammad. I think I know what went wrong with fplot. It apparently started from the 'n' end at x = -.5 and initially spaced x points close together. However during the long stretch in the middle where your v values are very nearly a constant zero, it got overconfident and began to space the x values farther and farther apart until near the other 'o' end at x = +.5 the last five x values out of a total of 121 it tried were:

x = -.208
x = -.144
x = -.016
x = +.240
x = +.500

This huge gap misses all the interesting variation in v at the right end and accounts for why the plot is so terribly inaccurate. It is the kind of behavior that functions like quad do in their calls to integrand functions which remain nearly constant for too long an interval.

My advice would be not to use fplot at all on the kind of stuff you're working with. Just use the straight 'plot' function. That way you know exactly what spacing is being used in the plotting. It is not being left up to some algorithm which is trying to be too smart for its own good.

Roger Stafford