functions with different conditions
조회 수: 6 (최근 30일)
이전 댓글 표시
If I have the conditions f(x) = {x^2, x>1 and x^4, x<=1}
How would I write this as a function with format f = @(x) ...... Can I do something like f=@(x) (x^2,x>1; x^4, x<=1);?
I also want to intergrate this afterwards like integral(f,0,2); for example.
댓글 수: 0
채택된 답변
Stephen23
2018년 12월 14일
>> f = @(x) x.^2.*(x>1) + x.^4.*(x<=1);
>> integral(f,0,2)
ans = 2.5333
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!