How to define an integral function of a piecewise function
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Abhisek Pradhan
le 16 Mar 2020
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.
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!