how to solve a system of equations in matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Alan Stevens
2020년 11월 29일
편집: Alan Stevens
2020년 11월 29일
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)
추가 답변 (1개)
Ameer Hamza
2020년 11월 29일
An alternate from symbolic toolbox
syms x
F = piecewise(x<=0, x+2, x>0, -x+2);
fplot(F, [-2 2])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!