0
Declined

arrayfun

husain_javan 8 ай бұрын updated by Pavel Holoborodko 8 ай бұрын

is there a way to use arrayfun for mp? I need to define a function in integral form. but integral only uses scalar values in its limits. If I use loops it would be a little slower.

Under review

Toolbox provides arrayfun and it works with mp variables. Do you have any issues using it? Please provide minimal and reproducible example of the issue.

```>> S(1).f1 = rand(1,5,'mp');>> S(2).f1 = rand(1,10,'mp');>> S(3).f1 = rand(1,15,'mp');
>> A = arrayfun(@(x) mean(x.f1),S)A =         0.5690631027410031794744327271473594        0.6602111831687765719500760042137699        0.4687452915777556405885206913808361    >> A = arrayfun(@(x) mean(x.f1),S,'UniformOutput',false)A =  1×3 cell array    {1×1 mp}    {1×1 mp}    {1×1 mp}```

hello Mr. Holoborodko. for example this function I can create:

```>>myfun = @(x)arrayfun( @(x) integral(@(t) t,eps, x, 'RelTol', eps), x);>>myfun([1 2])
ans =   0.500000000000000   2.000000000000000```

```>>mufun = @(x)arrayfun( @(x) quadgk(@(t) t,100*eps('mp'), x, 'RelTol', 100*eps('mp')), x);>>mufun(mp([1 2]))
ans =     [1x1 mp]    [1x1 mp]```

however when I try to give scalar without arrayfun, it works:

```mufun = @(x) quadgk(@(t) t,100*eps('mp'), x, 'RelTol', 100*eps('mp'));mufun(mp(2))
ans =     2.000000000000000000000000000000001```

what does it mean when it displays [1x1 mp] ?

Declined

This means that function returned array of cells, each cell is a "mp" number.
There is nothing wrong with it, you can use/see the actual number by  ans{1:2} or other indexing.

Why arrayfun returns the cell array in case of mp([1 2]) is a mystery, we will investigate it in more detail. I guess it is specific for non-standard types (like "mp").