English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

題目是 f(x) = (X-1)(X+2) COS(4X)
X = -5 ~ 5 step 建議是0.001
需要標示的有 Ymax= ? X = ?
Ymin=? X=?

不知道從何下手!!! 希望知道的大大能盡速回答唷!!!

越簡單越好嚕!!!

應該是能用上function 吧!!!

2006-12-27 15:43:22 · 3 個解答 · 發問者 阿鈞 2 in 電腦與網際網路 程式設計

電腦工程師 我把你用的寫進去

只是他出現 COS4 的名稱不對= =

希望你有看到我的補充 能盡快幫我解決問題!!!

謝謝!!!

2006-12-28 11:41:50 · update #1

3 個解答

Public Function Cos4(x As Single) As Single

Cos4 = (x - 1) * (x + 2) * Cos(4 * x)

End Function

Private Sub Command1_Click()
Dim x As Single, y As Single, tmp_x As Single, max As Single, min As Single, xa As Single, xi As Single

y = 0.001
x = -5 - y
max = -99
min = 99
Do
x = x + y
tmp_x = Cos4(x)
If (tmp_x > max) Then
max = tmp_x
xa = x
End If
If (tmp_x < min) Then
min = tmp_x
xi = x
End If
Loop While (x <= 5)

Print "X = " & xa & ", f(x) = " & max & " is max."
Print "X = " & xi & ", f(x) = " & min & " is min."

End Sub

2006-12-29 07:08:53 補充:
我再試了一次
沒看到你所說的問題啊

或者你把全部(3 個地方) 的 Cos4 改成 C4 試試看

如果有問題, 請來函討論. 不然, 我可能會錯失你再補充的疑點.

2006-12-28 01:31:22 · answer #1 · answered by JJ 7 · 0 0

要簡單就不一定要傷腦筋, 加一個listbox在屬性欄sorted設成true
將你的資料全部丟到listbox就完成了,取listbox第一筆與最後一筆就是最小與最大值.

2006-12-29 05:19:51 · answer #2 · answered by 速定 7 · 0 0

這還用不上 function 吧,當然也可以用
但如果前提要簡單,是應該不用

Private Type MaxMin
vMax As Double
x1 As Double
vMin As Double
x2 As Double
End Type

Private k As MaxMin

Private Sub Command1_Click()

Dim x As Double
Dim y As Double

For x = 5 To -5 Step -0.001

y = (x - 1) * (x + 2) * Cos(4 * x)

With k
If y > .vMax Then
.vMax = y: .x1 = x
ElseIf y < .vMin Then
.vMin = y: .x2 = x
End If

End With

Next
'
Debug.Print "YMax=" & k.vMax & vbTab & "X=" & k.x1
Debug.Print "YMin=" & k.vMin & vbTab & "X=" & k.x2

End Sub

2006-12-28 05:30:14 · answer #3 · answered by ? 6 · 0 0

fedest.com, questions and answers