help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Numerical integration with quadcc (resubmitted with MWE)


From: José Abílio Matos
Subject: Re: Numerical integration with quadcc (resubmitted with MWE)
Date: Sat, 08 Jun 2019 18:36:57 +0100

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

[Prev in Thread] Current Thread [Next in Thread]