how to solve a system of equations in matlab
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jens Petit-jean
le 29 Nov 2020
Réponse apportée : Ameer Hamza
le 29 Nov 2020
hello,
How do I solve this system of equations in matlab for F(-2:2) ?
f(x)= x+2 if x<=0
-x+2 if x>0
Apparently you can't use an if for this solution, but I don't really understand why either.
Thanks in advance
0 commentaires
Réponse acceptée
Alan Stevens
le 29 Nov 2020
Modifié(e) : Alan Stevens
le 29 Nov 2020
Try this
f = @(x) (x+2).*(x<=0) + (-x+2).*(x>0);
(x<=0) returns 1's where it's true and 0 where it's false. Similarly for (x>0)
Plus de réponses (1)
Ameer Hamza
le 29 Nov 2020
An alternate from symbolic toolbox
syms x
F = piecewise(x<=0, x+2, x>0, -x+2);
fplot(F, [-2 2])
0 commentaires
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!