My function of L-norm doesn't work
3 views (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Dyuman Joshi
on 12 Dec 2023
Edited: Dyuman Joshi
on 25 Feb 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
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!