작성일:
 
2010. 4. 16. 16:36
 

문제:

x=0 to 100일때
y=10x-x^2/10
y=4x-x^2/25-64
y=100x-x^2-2400
에 대해서

1. 함수 ttle='simple equation'
2. 함수의 xtitle='x', ytitle='y'
3. x와 t의 축 간격은 범위에 맞게 (여백 없게)
4. 각각의 함수는 서로 다른 점 또는 선 스타일로 구분
5. 각각의 함수의 최대값을 화면에 프린트
6. 각 함수에서 0의 값을 가지는 x값과 그 값의 갯수 프린트 (where 함수 사용
)

을 해결하시오




정답:

x=findgen(101)
y1=10*x-x^2/10
y2=4*x-(x^2/25)-64
y3=100*x-x^2-2400
ch='----------------------------------------------'
new='==============='

plot, x, y1, xrange=[0, 101], xstyle=1, color='3399EE'x, title='Simple Equation', xtitle='x', ytitle='y'
index=where(y1 eq 0, a)
print, index
print, new
print, a
print, ch
oplot, x, y2, color='99FFEE'x, thick=3, linestyle=2

index=where(y2 eq 0, a)
print, index
print, new
print, a
print, ch
oplot, x, y3, linestyle=1

index=where(y3 eq 0, a)
print, index
print, new
print, a
print, ch
print, max(y1), max(y2), max(y3)
end

; y1= 주황, y2=노랑, y3=흰색
; print, ch -> 줄 구분








출력값:

        0         100
===============
           2
----------------------------------------------
          20          80
===============
           2
----------------------------------------------
          40          60
===============
           2
----------------------------------------------
      250.000      36.0000      100.000



주의사항

1. Oplot의 경우 xrange, yrange 길이를 정할수 없기 때문에
맨 처음에 plot에서 max 값으로 가장 최대의 값을 확인 해 본후 출력 테스트 하는게 좋다 (라는 교수님의 말)

2. where 함수를 통해서, count 세는 방법

index=where(x eq 0, a)
print, index
print, a

따라서
index= x가 0이 되는 숫자값
a=위에 index의 숫자 갯수
print, x[index], 'Number of Solution: ', a

x[index]와 index 와의 차이
0-101까지 있기 떄문에
plot, x, y 이나 plot, y이나 같다.
이유는 x가 인덱스(기초값) 이기 떄문

if 20-80이라면
반드시! x[index]로 사용해야함