My function of L-norm doesn't work
Afficher commentaires plus anciens
I wrote a function file that calculates L^2 norm of the difference between 2 functions at the certain area:
function l = Lnorm(f1,f2)
l = sqrt(integral(@(x) (f1 - f2).^2, -8/5, 8/7));
end
Then i tested it with the code below:
f1 = x.^2;
f2 = x.^4;
Lnorm(f1, f2)
It sent me an error message: Error using integralCalc/finalInputChecks
Output of the function must be the same size as the input. If FUN is an array-valued integrand,
set the 'ArrayValued' option to true"
How to fix this?
Réponses (1)
Dyuman Joshi
le 12 Déc 2023
Modifié(e) : Dyuman Joshi
le 25 Fév 2024
f1 and f2 need to be defined as function handles.Notice the updated syntax used in the integrand to integral() as well -
f1 = @(x) x.^2;
f2 = @(x) x.^4;
Lnorm(f1, f2)
function l = Lnorm(f1,f2)
l = sqrt(integral(@(x) (f1(x) - f2(x)).^2, -8/5, 8/7));
end
1 commentaire
Dyuman Joshi
le 15 Mar 2024
Catégories
En savoir plus sur Vector Volume Data dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!