help-octave
[Top][All Lists]

## Re: Numerical integration with quadcc (resubmitted with MWE)

 From: Brett Green Subject: Re: Numerical integration with quadcc (resubmitted with MWE) Date: Sun, 9 Jun 2019 11:58:14 -0400

I had just forgotten to respond to the mailing list with the update; my apologies.

- Brett Green

On Sun, Jun 9, 2019 at 11:57 AM Brett Green <address@hidden> wrote:
Thank you! I was actually able to get it to work by doing something similar - I changed Vsame to the following:

function y = Vsame_fit(q)
[m,n] = size(q);
for k=1:m
for j=1:n
if q(k,j)<0.022913
y(k,j) = 0.98*tanh(200*q(k,j));
elseif q(k,j)<0.50274
y(k,j) = 1/(0.9*q(k,j)+1);
elseif q(k,j)<21.598
y(k,j) = 1/(1.046*q(k,j)+0.9266);
else
y(k,j) = 1/(0.9512*q(k,j)+2.89);
end
end
end
end

In either case, it seems to be an issue of the the relationship between the shape of the function's returned values and the shape of its inputs.

- Brett Green

On Sat, Jun 8, 2019 at 7:31 PM José Abílio Matos <address@hidden> wrote:
On Friday, 7 June 2019 23.21.02 WEST Przemek Klosowski wrote:
> octave:80> IntDemonstration(256.56/sqrt(25),1,3.4,200)
> ans =
>
>     0.29696   0.29299
>    -0.13252  -0.13075
>
> I am sorry but I ran out of time to figure out where this happens---you
> seem to carefully do element by element operations, so I must be missing
> one place where the auto-broadcast happens...

The problem occurs because of your custom function:

Using a simple example we can see that with a column vector the output of
Vsame is a row vector:
>> Vsame((1:3)')
ans =

0.97919   0.96611   0.95001

while for F0011 it is column vector:
>> F0011 ((1:3)')
ans =

0.303265
-0.135335
-0.038881

If we allow for it to return the same shape of the input vector it should
work:

function y = Vsame_fit(q)
y = zeros(size(q));
for k=1:length(q)
if q(k)<0.022913
y(k) = 0.98*tanh(200*q(k));
elseif q(k)<0.50274
y(k) = 1/(0.9*q(k)+1);
elseif q(k)<21.598
y(k) = 1/(1.046*q(k)+0.9266);
else
y(k) = 1/(0.9512*q(k)+2.89);
end
end
end

Notice the second line where we initialize y to have the same shape of q.

This should then work.

I hope this helps. :-)
--
José Matos

reply via email to