如何为交互绘图创建一个函数 [英] how do create a function for inter plotting
本文介绍了如何为交互绘图创建一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建一个用于交互绘图的函数
i有一个数据库已经连接并且功能完美
示例
表名1
220 10
210 0
200 -10
190 -40
我的标准是210我想插值为217然后我的答案是7比你的值205然后回答-5
解决方案
线性插值非常简单,请尝试:
功能 Interpolate(sd As SortedDictionary( 整数,整数),x As 整数)作为 Double
如果 x< sd.Keys.Min 或 x> sd.Keys.Max 然后
抛出 新的 System.ArgumentException()
结束 如果
Dim lastk 作为 整数
Dim v1,v2 As Double
对于 每个 k 在 sd .Keys
如果 x = k 那么
返回 Convert.ToDouble(sd.Item(k))
ElseIf x< k 然后
v1 = Convert.ToDouble(sd.Item(lastk))
v2 = Convert.ToDouble(sd.Item(k))
返回(v1 +(v2 - v1)*(x - lastk)/(k - lastk))
Else
lastk = k
结束 如果
下一步
结束 功能
Sub Main()
Dim sd 作为 新 SortedDictionary( 整数,整数)
sd.Add( 220 , 10 )
sd.Add( 210 , 0 )
sd.Add( 200 ,-10)
sd.Add(< span class =code-digit> 190 , - 40)
Dim xa( 3 )作为 整数
xa(< span class =code-digit> 0 )= 217
xa( 1 )= 205
xa( 2 )= 30
对于 每个 x 在 xa
Console.WriteLine( Interpolate {0},结果{1},x,Interpolate(sd,x))
下一步
结束 Sub
how do create a function for inter plotting
i have a database is already connected and function perfectly
example
table name 1
220 10
210 0
200 -10
190 -40
my standard is 210 i want interpolating for 217 then my answer is 7 than ur value 205 then answer -5解决方案Linear interpolation is pretty simple, try:
Function Interpolate(sd As SortedDictionary(Of Integer, Integer), x As Integer) As Double If x < sd.Keys.Min Or x > sd.Keys.Max Then Throw New System.ArgumentException() End If Dim lastk As Integer Dim v1, v2 As Double For Each k In sd.Keys If x = k Then Return Convert.ToDouble(sd.Item(k)) ElseIf x < k Then v1 = Convert.ToDouble(sd.Item(lastk)) v2 = Convert.ToDouble(sd.Item(k)) Return (v1 + (v2 - v1) * (x - lastk) / (k - lastk)) Else lastk = k End If Next End Function Sub Main() Dim sd As New SortedDictionary(Of Integer, Integer) sd.Add(220, 10) sd.Add(210, 0) sd.Add(200, -10) sd.Add(190, -40) Dim xa(3) As Integer xa(0) = 217 xa(1) = 205 xa(2) = 30 For Each x In xa Console.WriteLine("Interpolate {0}, result {1}", x, Interpolate(sd, x)) Next End Sub
这篇关于如何为交互绘图创建一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文