How can i integrate a piecewise function and then plot it?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to integrate a piecewise function that is so simple but when i use "piecewise" command, matlab tells me that there is a problem. I even tried integrating each piece but it's still not working and gives me wrong answers.
My code:
fun1=@(x)1;
fun2=@(x)0;
f=zeros(1,1000);
x=0;
for u=1:2
f(u)=integral(fun1,0,x,'ArrayValued',true);
x=x+1;
end
for u=3:1000
f(u)=integral(fun2,1,x,'ArrayValued',true);
x=x+1;
end
plot(f)
original question and functions i want to integrate (I'm stuck in first one):
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/533479/image.jpeg)
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation 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!