Tách hệ số của hàm số bậc n (1 người xem)

  • Thread starter Thread starter hsxrd
  • Ngày gửi Ngày gửi
Liên hệ QC

Người dùng đang xem chủ đề này

hsxrd

Thành viên mới
Tham gia
27/3/07
Bài viết
20
Được thích
10
Với một hàm số y=a(n).x^n+a(n-1).x^(n-1) + .... +a (0)
Nhờ các bạn giúp mình lập hàm nhặt ra các hệ số a(i) với. Cám ơn nhiều.
Mình sent file vidu.xls
 

File đính kèm

Lần chỉnh sửa cuối:
Tach he so bac n

Bạn có thể viết 1 hàm số như sau:

Private Function tachheso(hamso As String, bac As Integer)
Dim j, i, m As Integer
Dim a(0 To 100)
Dim b(0 To 100)
hamso = Trim(hamso)
' Tim he so bac 0
For j = Len(hamso) To 1 Step -1
If Mid(hamso, j, 1) = " " Then
a(0) = Right(hamso, Len(hamso) - j)
For m = 1 To Len(a(0))
If Mid(a(0), m, 1) = "x" Then
a(0) = 0
Exit For
End If
Next
Exit For
End If
Next
' Tim cac he so bac 1,2,3,4,...
For j = 1 To Len(hamso) Step 1
If Mid(hamso, j, 1) = "x" Then
If Mid(hamso, j + 1, 1) = " " Or Mid(hamso, j + 1, 1) = "" Then
i = 1
Else: i = Mid(hamso, j + 1, 1)
End If
For m = j To 1 Step -1
If Mid(hamso, m, 1) = " " Then
a(i) = Trim(Mid(hamso, m, j - m))
Exit For
End If
Next
End If
Next
tachheso = a(bac)
End Function
 
Bạn có thể viết 1 hàm số như sau:

Private Function tachheso(hamso As String, bac As Integer)
Dim j, i, m As Integer
Dim a(0 To 100)
Dim b(0 To 100)
hamso = Trim(hamso)
' Tim he so bac 0
For j = Len(hamso) To 1 Step -1
If Mid(hamso, j, 1) = " " Then
a(0) = Right(hamso, Len(hamso) - j)
For m = 1 To Len(a(0))
If Mid(a(0), m, 1) = "x" Then
a(0) = 0
Exit For
End If
Next
Exit For
End If
Next
' Tim cac he so bac 1,2,3,4,...
For j = 1 To Len(hamso) Step 1
If Mid(hamso, j, 1) = "x" Then
If Mid(hamso, j + 1, 1) = " " Or Mid(hamso, j + 1, 1) = "" Then
i = 1
Else: i = Mid(hamso, j + 1, 1)
End If
For m = j To 1 Step -1
If Mid(hamso, m, 1) = " " Then
a(i) = Trim(Mid(hamso, m, j - m))
Exit For
End If
Next
End If
Next
tachheso = a(bac)
End Function
Bạn có thể viết một thủ tục (macro trong excel) để đọc một hàm số y=ax^3+bx^2+cx+d được không ?
 
Web KT

Bài viết mới nhất

Back
Top Bottom