一个与数学相关的问题!(20分)

  • 主题发起人 主题发起人 jasonbruc
  • 开始时间 开始时间
J

jasonbruc

Unregistered / Unconfirmed
GUEST, unregistred user!
我想知道在delphi中有没有计算余玄函数的功能,谢谢!
 
有啊 用y=cos(x)即可
这是以前的一个画余玄曲线的东东 很简单的
下面是完整的代码:
----------------------------------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var i,j:integer; x,y:real;
halfheight:integer;
begin

halfheight:=form1.Height div 2;

for i:=1 to trunc(form1.Width) do
begin
x:=i*(4*PI/form1.Width);
y:=cos(x); //halfheight*0.7
j:=trunc(y*100)+halfheight;
canvas.Pixels[i,j]:=clred;
end;

x:=3*form1.Width/4; //画竖线
i:=trunc(x);
with canvas do
begin
pen.Color:=clblue;
moveto(i,0);
lineto(i,form1.Height);
end;
end;

procedure TForm1.FormPaint(Sender: TObject);
var x,y:real;i,j:integer;
begin
x:=form1.Width/4; //坐标系
i:=trunc(x);
y:=form1.Height/2;
j:=trunc(y);

with canvas do
begin
moveto(i,0);
lineto(i,form1.Height);
moveto(0,j);
lineto(form1.Width,j);
end;

end;

end.
 
我不是要画余玄曲线,是这样的我想实现的是但我输入一个值的时候比如说45
我想得到的返回数是1
 
那就用cos()函数啊~

procedure TForm1.Button2Click(Sender: TObject);
begin
edit2.Text:=floattostr(cos(PI*strtofloat(Edit1.Text)));
end;
 
但是它不能计算所有角度的值啊(1-360度)
 
我这儿有一个函数,你试试看。
function Cos(x: Real): String;
var
tmp: Extended;
tmpStr: String;
begin
tmp := System.cos((pi/180) * x);
if abs(tmp) < 0.00000001 then
tmp := 0;
if (tmp = 0) then
tmpStr := '0'
else
Str(tmp:5:3, tmpStr);
result := tmpStr;
end;
 
delphi的函数足够了呀?
〉〉但是它不能计算所有角度的值啊(1-360度)
什么意思??

在数学上可以用泰勒展开,自己写个循环程序,
循环次数可以控制你想要的精度
我估计自己写的这个算起来会很慢
 
后退
顶部