How to define an integral function of a piecewise function
2 次查看(过去 30 天)
显示 更早的评论
Hello!
I want to define an integral function but I have a problem with the integral function. This is my code:
syms s t
figure(1)
P = [0.5 1.25 2 4.5 5 7.25];
for i=1:4
subplot(4,2,i)
hold on
a = @(s) (s-P(i))/(P(i+1)-P(i));
b = @(s) (P(i+2)-s)/(P(i+2)-P(i+1));
f(i) = piecewise(s<=P(i),0, P(i)<s<=P(i+1),a(s), P(i+1)<s<=P(i+2),b(s), s>P(i+2),0);
fplot (f(i),[0,P(4)])
hold off
grid
subplot(4,2,i+1)
hold on
F = @(t) integral(f(i), 0, t);
fplot(F(t),[0,P(4)])
hold off
grid
end
In particular, there is no problem with the function f, however Matlab returns the following error:
Error using integral (line 82)
First input argument must be a function handle.
Error in example_f_int>@(t)integral(f(i),0,t) (line 19)
F = @(t) integral(f(i), 0, t);
Error in example_f_int (line 20)
fplot(F(t),[0,P(4)])
There is a way to solve this error and finaly plot the F funciont?
Thanks, any help would be appreciated!
0 个评论
回答(1 个)
Abhisek Pradhan
2020-3-16
Intergral function take a function handle as its first argument. Adding @(arg) Infront of piecewise () may work.
Refer the following link for more details on how to use integral function.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!