作者bcs (= ="frailty..gggg XD)
看板Statistics
標題[問題] R 畫間斷函數
時間Fri Apr 13 20:07:54 2007
f(x)= sin(x) if -5<=x<=0
e^x if 1<=x<10
R code:
f<-function(x){
if((x>=-5) && (x<=0)) sin(x)
else if((x>=1) && (x<=100)) exp(x)
}
plot(f,-5,10,type="p")
畫出的圖卻是sin(x) 請問上面哪編錯了?
謝謝
--
這因果報應,佛神都逃不了,何況是人!善哉 ╮(﹀_﹀")╭
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.247.214
推 bugle:plot(seq(-5,10,0.1),f(seq(-5,10,0.1)),type='p') 04/13 20:14
推 bugle:上面是plot函數的正確用法,但因為你的f寫的有缺陷 04/13 20:17
→ bugle:所以只會畫到sin(x) 04/13 20:17