Use of 'ArrayValued' in Matlab numerical integration
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Renzo Del Fabbro
am 23 Sep. 2022
Beantwortet: Torsten
am 23 Sep. 2022
Why in Matlab numerical integration
f = @(x) 5;
integral(f,0,2,'ArrayValued',true)
needs 'ArrayValued',true ... while
f = @(x) x;
integral(f,0,2)
don't need it?
0 Kommentare
Akzeptierte Antwort
Davide Masiello
am 23 Sep. 2022
Bearbeitet: Davide Masiello
am 23 Sep. 2022
Let's take a look at the error message
f = @(x) 5;
integral(f,0,2)
The important line here is "Output of the function must be the same size as the input".
I believe this could be due to the fact that integral passes a whole array of x-values in the attempt to integrate the function within the default tolerances.
If your functions does not depend on x, then the ouput would be a single scalar and therefore different from the input.
Specifing 'ArrayValued' as true, you tell the solver that the output must be an array the same size as the x passed to it.
In fact, you could try to integrate an equivalent function where the dependance on x is explicit, and it would work without specifying 'ArrayValued' as true.
f = @(x) 5*(x-x+1);
integral(f,0,2)
10
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!