首页 \ 问答 \ 指数泰勒级数(Exponential Taylor Series)

指数泰勒级数(Exponential Taylor Series)

这是我到目前为止的代码,因为我仍在试图弄清楚如何设置它,所以有点乱,但我无法弄清楚如何获得输出。 该代码应该采用指数的泰勒级数多项式,并检查获得近似值所需的迭代次数。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*Prototype for functions used*/
double factorial (int);

int main()
{
   double input = 0;
   double exp_val;
   double delta = 1;
   int f =0;
   int n = 0;
   double taylor;
   int total;
   printf("Plese enter the exponent to check for convergence:\n");
   scanf("%lf", &input);
   exp_val = exp(input);
   printf("  #     Iter      e^X      Sum     Diff\n");
   printf("----   ------   -------   -----  --------");

   while(delta > 0.00001)
   {
      f = factorial(n);
      taylor = ((pow(input,n))/ f);
      delta = (exp_val - taylor);
      printf("%d %f %f %f/n", (n+1), exp_val, taylor, delta);
      n++;
   }
   system("pause");


}

double factorial (int n)
{
  int r = 0;
  int sum = 1;
  int total = 0;
  if (n == 0)
    return total =1;
  else
  {
     for(r; r<n; r++)
     {
        sum = sum * r;
        total = sum + 1;

     }

     return total;
  }

}

This is the code I have so far, which is a little messy since I am still trying to figure out how to set it up, but I cannot figure out how to get the output. This code is supposed to take a Taylor Series polynomial of an exponential, and check the amount of iterations it takes to get the approximation.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*Prototype for functions used*/
double factorial (int);

int main()
{
   double input = 0;
   double exp_val;
   double delta = 1;
   int f =0;
   int n = 0;
   double taylor;
   int total;
   printf("Plese enter the exponent to check for convergence:\n");
   scanf("%lf", &input);
   exp_val = exp(input);
   printf("  #     Iter      e^X      Sum     Diff\n");
   printf("----   ------   -------   -----  --------");

   while(delta > 0.00001)
   {
      f = factorial(n);
      taylor = ((pow(input,n))/ f);
      delta = (exp_val - taylor);
      printf("%d %f %f %f/n", (n+1), exp_val, taylor, delta);
      n++;
   }
   system("pause");


}

double factorial (int n)
{
  int r = 0;
  int sum = 1;
  int total = 0;
  if (n == 0)
    return total =1;
  else
  {
     for(r; r<n; r++)
     {
        sum = sum * r;
        total = sum + 1;

     }

     return total;
  }

}

原文:https://stackoverflow.com/questions/22122846
更新时间:2023-09-21 09:09

最满意答案

感谢@Phorgz&@GabeRogan指引我朝着正确的方向前进。 Delaunay Triangulation绝对是最佳选择,即使将画布更新为动画,结果也非常快速。

我最终使用了npm包更快delaunay ,它使用分而治之算法对随机生成的点进行三角测量。

以下是我在画布上绘制的结果,点随着飞机移动而更新:

德劳内


Thanks to @Phorgz & @GabeRogan for pointing me in the right direction. Delaunay Triangulation was definitely the way to go and it ended up being very fast, even when updating the canvas as an animation.

I did end up using the npm package faster-delaunay which uses the divide and conquer algorithm to triangulate the randomly generated points.

Here is a result of what I have drawn on the canvas that updates as the points move around the plane:

delaunay

相关问答

更多
  • 一个好的解决方案是从随机点开始(使用您的首选分布)并应用一些三角测量算法。 其中,Delaunay三角剖分是一个很好的候选者,因为它的计算复杂度和代码可用性都很低。 A good solution is to start with random points (with your preferred distribution) and apply some triangulation algorithm. Among these, the Delaunay triangulation is a good c ...
  • 问题1:为什么这些点是随机顺序的? 如果是,则必须对它们进行排序,以便用直线连接连续点会产生凸多边形。 如何订购它们 - 例如,通过运行凸包算法(尽管可能还有更简单的方法)。 订购后,按照此处的说明计算区域。 - 问题2更简单。 半平面由具有隐式方程a*x+b*y+c=0的单个线定义; a*x+b*y+c <= 0 (注意不等式)的所有点(x,y)都在半平面的“后面”。 现在,您需要至少三个平面,以便它们的负半空间的交点关闭(这是必要的,但不是充分的条件)。 如果交叉点已关闭,则它将是凸多边形。 我建议你维 ...
  • 如果您确定几何体是否始终是凸的,那么您真正需要的是凸壳算法。 凸壳:此算法通过仅连接3d空间中给定点集的最外侧顶点来创建网格。 显然,您将松开凸结构内部的顶点,不会在任何三角形中使用。 这仅适用于凸形。 下面是凸壳结构的一个很好的例子。 有许多库实现了Convex hulling算法。 例如:CGAL,BulletPhysics和OpenMesh。 如果您正在寻找快速建造凸壳的方法,QuickHull是最好的地方。 http://www.qhull.org What you exactly need is ...
  • 从给定的角度来看,施一条直线。 测试线与每个三角形的交点,并计算在点的同一侧找到的所有交点。 如果这个计数是奇数,你就在里面。 为了简化计算,对线使用x=x0 , y=y0并在XY平面上投影所有内容。 使用如何确定点是否在2D三角形中? 最后检查交叉点的z值。 From the given point, cast a straight line. Test intersection of the line with every triangle and count all intersections fou ...
  • 如何遵循一个简单的GrahamScan Algo ...这是应该做的伎俩。 How About Following A simple GrahamScan Algo... That's should Do the Trick.
  • 感谢@Phorgz&@GabeRogan指引我朝着正确的方向前进。 Delaunay Triangulation绝对是最佳选择,即使将画布更新为动画,结果也非常快速。 我最终使用了npm包更快delaunay ,它使用分而治之算法对随机生成的点进行三角测量。 以下是我在画布上绘制的结果,点随着飞机移动而更新: Thanks to @Phorgz & @GabeRogan for pointing me in the right direction. Delaunay Triangulation was de ...
  • Delaunay Triangulation是你的朋友! 如果您使用Google这个术语,那么有很多可用的资源,其背后的数学/逻辑并不太难。 快速制作(但完全可行)有点困难,但这完全取决于您的要求。 Delaunay Triangulation is your friend! There are lots of resources available about it if you Google the term, and the math/logic behind it isn't too tough. ...
  • 建议: 不要使用getGraphics()来获取Graphics对象,因为如果执行任何重绘(不受控制的话getGraphics() ,获得的Graphics对象将不会持久存在。 而是绘制到BufferedImage并让JPanel或JComponent在其paintComponent覆盖中绘制BufferedImage,或者将您的图像数据添加到某种Collection的集合中,并让paintComponent覆盖方法使用绘制图像的信息迭代Collection。 不要直接在顶级窗口(如JFrame或JAppl ...
  • 计算机图形中的这种集合交互通常使用索引来实现。 class Point { float x,y; } class Triangle { unsigned int indices[3]; // indices in std::vector } std::vector points; std::vector triangles; 与指针解决方案相比,主要优点是您可以在着色器程序中使用此类索引引用。 编辑:通过已知索引删除顶点的代码示例(未测试) ...
  • 假设您的三角形是A:A1A2A3和B:B1B2B3 1)计算N1,A1A2和A1A3的归一化叉积。 2)测试B由A“看”,即N1•A1B1> 0。 3)计算N2,B1B2和B1B3的归一化交叉积。 如果你想测试'严格面对',那么测试N1•N2 == -1(其中•是点积)。 对于不太严格的面对,你可以测试N1•N2 - ( - 1)<一些小值。 正如@BenAaronson指出的那样,你可能想通过测试(A1A2,A1A3)和(B1B2,B1B3)来共同测试rectn是否在同一平面上。 如果O是原点,则测试N1 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)