高斯消元 - 在k点内插入范围(1,...,n)内的结果。 [英] Gauss elimination - interpolate the results within the range (1, …, n) in k points.

查看:56
本文介绍了高斯消元 - 在k点内插入范围(1,...,n)内的结果。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到高斯消除结果的插值。我已经对插值进行了编码,但输出中的位置没有出现,或者有时出现错误的位置。



double interpolationSearch(double X [],int n,int e)

{

int start,结束,pos;

start = 0;

end = n - 1;



while(start< ; =结束&& e> = X [开始]&& e< = X [结束])

{



pos = start +(((double)(end - start)/(X [end] - X [start]))*(e - X [start]));



if(X [pos] == e)

返回pos;

if(e> X [pos])

start = pos + 1;

else

end = pos - 1;

}

返回-1;

}



我尝试过:



有人可以指导我吗?我试过改变了while循环很多但仍然无法解决它

I need to find interpolation for the result of gauss elimination. I have coded the interpolation but the position in the output is not appearing or sometimes wrong position appears.

double interpolationSearch(double X[], int n, int e)
{
int start, end, pos;
start = 0;
end = n - 1;

while (start <= end && e >= X[start] && e <= X[end])
{

pos = start + (((double)(end - start) / (X[end] - X[start]))*(e - X[start]));

if (X[pos] == e)
return pos;
if (e > X[pos])
start = pos + 1;
else
end = pos - 1;
}
return -1;
}

What I have tried:

Can somebody guide me? I have tried changing the while loops alot but still could not get it solved

推荐答案

不要改变while循环 - 停下来,思考并弄清楚什么是错的。这是你的作业,这意味着任务是

1)阅读说明

2)设计解决方案

3)编码设计

4)测试代码

5)找出为什么它不能完全按照你想要的方式工作

6)回到4, 3,2和/或1,直到你说得对。



编写代码只是这项任务的一小部分:重要的事情是在1& 2,复杂的部分是4& 5.对于每个项目,你可以期望绕过几次循环,特别是在你开始的时候。



那你花了多少时间和精力在1之间和3?这一点很重要,因为越早找到 - 并且修复 - 问题就越容易,你就越少扔掉。



所以,这取决于你。

幸运的是,你有一个工具可以帮助你找到什么正在进行:调试器。在函数的第一行放置一个断点,然后通过调试器运行代码。然后查看您的代码,并查看您的数据并找出手动应该发生的事情。然后单步执行每一行检查您预期发生的情况正是如此。如果不是,那就是当你遇到问题时,你可以回溯(或者再次运行并仔细观察)以找出原因。


对不起,但我们不能为你做到这一点 - 时间让你学习一门新的(非常非常有用的)技能:调试!
Don't "change the while loops alot" - stop, think and work out what is wrong. This is your homework, and that means the task is
1) Read the instructions
2) Design a solution
3) Code the design
4) Test the code
5) Find out why it doesn't do exactly what you want
6) Go back to 4, 3, 2, and / or 1 until you have it right.

Writing the code is a small part of this task: the important stuff is done in 1 & 2, and the complicated part is 4 & 5. You can expect to go round the loop several times for every project, particularly when you are getting started.

So how much time and effort did you expend between 1 and 3? This is important, because the earlier you find - and fix - problems the easier it is and the less you have to throw away.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!


这篇关于高斯消元 - 在k点内插入范围(1,...,n)内的结果。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆