- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
如何用脚本计算出最符合的值?
大家好!
如图: 有若干组数据、它们的数据比较接近。
每组数据有大、小两个值。
如何通过脚本来求出图中红色的水平线的最优值:
要求这个水平线与能这组数据最多的其中一个端点接近、要求这条线是水平的。
我试着用最小二乘法来回归、但还是不理想。
谢谢各位专家!
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
回复: 如何用脚本计算出最符合的值?
x = Round( Beta[1] + 5 * Beta[2], 0 );
4 REPLIES 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
回复: 如何用脚本计算出最符合的值?
dt = Current Data Table();
m = Mean( dt[0, 2 :: 3] );
Column( "S" ) << Formula( If( Abs( H - m ) > Abs( L - m ), L, H ) );
dt << run formulas;
Column( "S" ) << deleteFormula;
ar = dt << GetAsMatrix( {4, 1} );
{Beta, VarBeta} = Least Squares Solve( ar[0, 1], ar[0, 2] );
x = round(Beta[1],0);
Thanks Experts!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
回复: 如何用脚本计算出最符合的值?
Hi Lala
我的理解是你需要一个值,这个值得取值范围为所有数据的最小值到最大值这个范围。这个值需要和11个组的两个端点进行条件判断。
我的思路是既然是一根水平线,因此f(x)=b。换个方法就是取一个值b,让b距离11个组最近的那个点的值的求和最小。
即,假设结果为b。那么整体的函数就是求, Y=min(abs(y1max-b),(y1min-b))+min(abs(y2max-b),(y2min-b))+...min(abs(y11max-b),(y11min-b))。对Y求最小。
你可以尝试整理这个函数然后求Y最小值时b的值,然后带入函数f(x)=b。应该就可以了。
心若止水
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
回复: 如何用脚本计算出最符合的值?
非常感谢!
假如这样的数据超过一百组、也要这样编辑公式吗?
我还是没有想到好方法。
再次感谢!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
回复: 如何用脚本计算出最符合的值?
x = Round( Beta[1] + 5 * Beta[2], 0 );