How can I construct a triangle function, when I tested one using 'integral(fun.-pi,pi)', error occurred.
3 views (last 30 days)
Show older comments
Thamrongsin Siripongsakul
on 2 Mar 2023
Commented: Thamrongsin Siripongsakul
on 2 Mar 2023
function [a] = triangle(n)
a=zeros(size(n));
a(n>=0 & n<=pi)=pi-n;
end
--------------------
>> fun = @(x)triangle(x)
fun =
@(x)triangle(x)
>> integral(fun,-pi, pi)
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in triangle (line 3)
a(n>=0)=pi-n;
Error in @(x)triangle(x)
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
I used to define a step function like this and it works. Why did it not work this time?
0 Comments
Accepted Answer
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!