How to draw the graph of a function that has different structure in its different domain
조회 수: 5 (최근 30일)
이전 댓글 표시
Dear all suppose i want to find the graph of a function such that f(x)=4+x/(2+x^2) when x>0 and f(x)=4-x/(2-x^2) for x<=0 .How i can draw the two different forms of a function in different domain in a single graph with x-axis [-1,1].
댓글 수: 0
채택된 답변
Star Strider
2015년 12월 13일
Using logical indexing operations, this works:
f = @(x) (4+x./(2+x.^2)).*(x>0) + (4-x./(2-x.^2)).*(x<0); % Function
x = linspace(-1, 1, 250); % Define ‘x’
figure(1)
plot(x, f(x)) % Plot
grid
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Argument Definitions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!