求解y=x+x^2+x^3 |
答題得分者是:elva349
|
mirood
一般會員 發表:10 回覆:27 積分:7 註冊:2007-02-28 發送簡訊給我 |
|
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
mirood
一般會員 發表:10 回覆:27 積分:7 註冊:2007-02-28 發送簡訊給我 |
|
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
你可以試試看寫個副程式,再用for迴圈等方式來簡化
ex: [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop //--------------------------------------------------------------------------- #pragma argsused using namespace std; int mm(int a,const int b) { for(int i=1;i<=b;i ) { a=a*i; } return a; }; int main(int argc, char* argv[]) { int a=2; y=a mm(a,2) mm(a,3); cout< return 0; } [/code] ===================引 用 mirood 文 章=================== 是啊~ 想不到一個頭緒~ |
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
|
mirood
一般會員 發表:10 回覆:27 積分:7 註冊:2007-02-28 發送簡訊給我 |
|
mirood
一般會員 發表:10 回覆:27 積分:7 註冊:2007-02-28 發送簡訊給我 |
|
暗黑破壞神
版主 發表:9 回覆:2301 積分:1627 註冊:2004-10-04 發送簡訊給我 |
|
Coffee
版主 發表:31 回覆:878 積分:561 註冊:2006-11-15 發送簡訊給我 |
|
mirood
一般會員 發表:10 回覆:27 積分:7 註冊:2007-02-28 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
Inverse Function Left f be a one-to-one function. The inverse of f, denoted by f -1, is the unique function which is defined on the range of f and satisfies the equation f(f -1(x)) = x, for all x in the range of f . for example, f(x) = x3 we begin by setting f(f -1(x)) = x since f is the cubing function, we must have f(f -1(x)) = [f -1(x)]3 so that [f -1(x)]3 = x Taking cube roots we have f -1(x) = x1/3 -------------------------------------------------------------------------- 先確定 y=x x^2 x^3 是不是 one-to-one function... 這是微積分教科書寫的, 再不行的話可能還要去挖工程數學了.....^_^ |
fatmoon1
初階會員 發表:3 回覆:29 積分:36 註冊:2004-05-24 發送簡訊給我 |
由y=x+x^2+x^3
以 x=1/2 代入 y=7/8 以 x=1 代入 y=3 所以可知 y=1 時 x在 1/2 到 1 之間 如此 就可以 由 x 從 1/2 到 1 取值 (如 0.6,0.7,0.8,0.9) 去求得 y 值 找出最相近的 x 值 當然如果能用 泰勒展開式 是最好的了 ===================引 用 mirood 文 章=================== 各位大大: y=x (x*x) (x*x*x)解y值利用pow可以很簡單解決~ 但是小弟輸入任意值y,要如何解x值呢? 例如:利用y=1,x=?(小數點要第六位)
------
才疏學淺 |
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
用程式簡單畫出 Y = X + X2 X3 圖形,
看樣子此函式應該是一個 one-to-one function. 只是不知道能否導出它的 Inverse function? 個人觀點, 純屬臆測...^_^ 程式碼下載: http://delphi.ktop.com.tw/download.php?download=upload/4720bef6d4a54_TestC018.zip [code cpp] //--------------------------------------------------------------------------- #ifndef fMainH #define fMainH //--------------------------------------------------------------------------- #include #include #include #include <Forms.hpp><br />//--------------------------------------------------------------------------- class TForm1 : public TForm { __published: void __fastcall FormResize(TObject *Sender); void __fastcall FormPaint(TObject *Sender); void __fastcall FormCreate(TObject *Sender); private: bool calculated; double left, bottom, right, top;//Scale void __fastcall scale(double left, double bottom, double right, double top); double __fastcall RatioX(); double __fastcall RatioY(); int __fastcall f2pX(double x); int __fastcall f2pY(double y); void __fastcall InitialCanvas(); void __fastcall moveto(TCanvas *c, double x, double y); void __fastcall lineto(TCanvas *c, double x, double y); void __fastcall line(TCanvas *c, double x0, double y0, double x1, double y1); void __fastcall text(TCanvas *c, double x, double y, AnsiString s); double __fastcall WidthOf(int pixels); double __fastcall HeightOf(int pixels); public: __fastcall TForm1(TComponent* Owner); // //y=f(x)=x x^2 x^3 double __fastcall f(double x){return x x*x x*x*x;}; // bool __fastcall MAXMIN(double* v, int len, double* M, double* N); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif [/code] [code cpp] //--------------------------------------------------------------------------- #include #pragma hdrstop #include "fMain.h" #include //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- #define max(a, b) (((a) > (b)) ? (a) : (b)) #define min(a, b) (((a) < (b)) ? (a) : (b)) //--------------------------------------------------------------------------- double w=0.1; double XX[1000],YY[1000]; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner) { } //--------------------------------------------------------------------------- bool __fastcall TForm1::MAXMIN(double* v, int len, double* M, double* N) { *M=-MaxInt/1.0; *N= MaxInt/1.0; for(int i=0;i *N=min(*N,v[i]); } return M>N; } //--------------------------------------------------------------------------- void __fastcall TForm1::scale(double left, double bottom, double right, double top) { this->left=left; this->bottom=bottom; this->right=right; this->top=top; } //--------------------------------------------------------------------------- double __fastcall TForm1::RatioX() { if(left==right)return 1; return (ClientWidth-2)/(right-left); } //--------------------------------------------------------------------------- double __fastcall TForm1::RatioY() { if(top==bottom)return 1; return (ClientHeight-2)/(top-bottom); } //--------------------------------------------------------------------------- int __fastcall TForm1::f2pX(double x) { int ret=(x-left)*RatioX() 1; return (int)ret; } //--------------------------------------------------------------------------- int __fastcall TForm1::f2pY(double y) { float ret=(float)ClientHeight-(y-bottom)*RatioY()-2; return (int)ret; } //--------------------------------------------------------------------------- void __fastcall TForm1::moveto(TCanvas *c, double x, double y) { c->MoveTo(f2pX(x), f2pY(y)); } //--------------------------------------------------------------------------- void __fastcall TForm1::lineto(TCanvas *c, double x, double y) { c->LineTo(f2pX(x), f2pY(y)); } //--------------------------------------------------------------------------- double __fastcall TForm1::WidthOf(int pixels) { if(RatioX()==0)return 0; return (int)(pixels/RatioX()); } //--------------------------------------------------------------------------- double __fastcall TForm1::HeightOf(int pixels) { if(RatioY()==0)return 0; return (int)(pixels/RatioY()); } //--------------------------------------------------------------------------- void __fastcall TForm1::line(TCanvas *c, double x0, double y0, double x1, double y1) { c->MoveTo(f2pX(x0), f2pY(y0)); c->LineTo(f2pX(x1), f2pY(y1)); } //--------------------------------------------------------------------------- void __fastcall TForm1::text(TCanvas *c, double x, double y, AnsiString s) { TBrushStyle old_style=c->Brush->Style; try{ c->Brush->Style=bsClear; int TW=c->TextWidth(s); int TH=c->TextHeight(s); TRect r=Rect(0,0,TW 1,TH 1); OffsetRect(r,f2pX(x),f2pY(y)); DrawText(c->Handle,s.c_str(),s.Length(),&r,DT_CENTER||DT_SINGLELINE); } __finally{ c->Brush->Style=old_style; } } //--------------------------------------------------------------------------- void __fastcall TForm1::InitialCanvas() { Canvas->Pen->Width=1; Canvas->Pen->Color=clGray; Canvas->Pen->Style< // Canvas->Brush->Color=Color; Canvas->Brush->Style=bsSolid; Canvas->Font->Name="ARIAL"; // Canvas->Font->Color=clWhite; Canvas->Font->Height=20; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Color=clBlack; memset(&XX,0,sizeof(XX)); memset(&YY,0,sizeof(YY)); for(int i=0;i<1000;i ){ int x=w*(i-500); XX[i]=x; YY[i]=f(x); } double M, N; if(MAXMIN(YY,1000,&M,&N)){ scale(XX[0],N,XX[999],M); } calculated = true; } //--------------------------------------------------------------------------- void __fastcall TForm1::FormResize(TObject *Sender) { Repaint(); } //--------------------------------------------------------------------------- void __fastcall TForm1::FormPaint(TObject *Sender) { if(calculated){ InitialCanvas(); //x-axis line(Canvas,left,0,right,0); //y-axis line(Canvas,0,bottom,0,top); //Draw Line (XX[], YY[]) Canvas->Pen->Width=2; Canvas->Pen->Color=clYellow; for(int i=0;i<1000;i ){ if(i==0) moveto(Canvas,XX[i],YY[i]); else lineto(Canvas,XX[i],YY[i]); } /* Draw Text */ //X TFontStyles style; Canvas->Font->Style=style< text(Canvas,t,0,"X"); //Y text(Canvas,WidthOf(1),top-HeightOf(5),"Y"); //原點 text(Canvas,0,0,"(0,0)"); //Title Canvas->Font->Height=24; Canvas->Font->Color=clFuchsia; Canvas->Font->Style=style>>fsItalic; text(Canvas,left,top,"圖解: Y=X X^2 X^3"); } } //--------------------------------------------------------------------------- [/code] |
GrandRURU
站務副站長 發表:240 回覆:1680 積分:1874 註冊:2005-06-21 發送簡訊給我 |
|
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
|
mirood
一般會員 發表:10 回覆:27 積分:7 註冊:2007-02-28 發送簡訊給我 |
|
jow
尊榮會員 發表:66 回覆:751 積分:1253 註冊:2002-03-13 發送簡訊給我 |
簡單求解...^_^
[code cpp] //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { bool b; AnsiString S="x not found"; double x = find(3.0, 0.0000000001,&b); if(b)S.sprintf("%.6f(驗算: %.6f)",x,f(x)); Caption = S; } //--------------------------------------------------------------------------- double __fastcall TForm1::find(double y, double precision, bool* found) { double m,d; double h= fabsl(y); double l=-fabsl(y); *found=false; while(!(*found)&&l<=h){ m=(l h)/2.0; d=(f(m)-y); *found=fabsl(d) < precision; if(!*found){ if(d<0) l=m; else h=m; } } if(*found)return m; return l; } //--------------------------------------------------------------------------- [/code]
編輯記錄
jow 重新編輯於 2007-10-27 04:01:19, 註解 無‧
jow 重新編輯於 2007-10-27 04:02:55, 註解 無‧ jow 重新編輯於 2007-10-27 04:07:23, 註解 無‧ jow 重新編輯於 2007-10-27 04:08:41, 註解 奇怪? 程式碼貼不齊???‧ jow 重新編輯於 2007-10-27 04:09:18, 註解 無‧ jow 重新編輯於 2007-10-27 04:10:45, 註解 無‧ jow 重新編輯於 2007-10-27 04:12:01, 註解 無‧ jow 重新編輯於 2007-10-27 04:17:42, 註解 無‧ |
elva349
一般會員 發表:15 回覆:21 積分:17 註冊:2007-04-17 發送簡訊給我 |
我只能想到這種做法... ~只考慮 "正"數 的話
Edit1->Text 填入 y 輸出在 Edit2->Text [code cpp] double Pre,X,Y,Y1,Y2; void __fastcall TForm1::Button1Click(TObject *Sender) { Y= StrToFloat (Edit1->Text); Pre =1; X=0; Y1=0; for (int T=0 ; T<7 ; T ) //精確度 到小數點第6位 { for ( ; Y1 Y2=Y1; Y1=X X*X X*X*X; } if (Y1==Y) { X=X-Pre; break; } Y1=Y2; X=X-Pre-Pre; Pre=Pre/10; } Edit2->Text=X; } [/code]
編輯記錄
elva349 重新編輯於 2007-11-01 18:05:07, 註解 沒考慮到有負的...‧
|
arisaka_matsuri
高階會員 發表:25 回覆:205 積分:231 註冊:2003-10-19 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |