PDA

View Full Version : سوال: الگوریتم محاسبه مشتق وانتگرال گیری



mehdi_vatan
یک شنبه 04 مرداد 1388, 07:06 صبح
می خواهم برنامه ای بنویسم که مشتق و انتگرال یک عبارت را محاسبه کند اگه کسی می تونه الگوریتم آن را تو ضیح بده یا منبعی را معرفی بکند.(البته هم به صورت عددی و هم سمبولیک)

یک سوال دیگری که داشتم این است که آیا منبعی هست که در رابطه با الگوریتم های حل مسائل مختلف ریاضی باشد.

mortezamsp
دوشنبه 05 مرداد 1388, 18:41 عصر
با سلام.

لینک های ریاضی:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html
این به زبان java هست البته.
و این به زبان cpp
http://www.cplusplus.happycodings.com/Mathematics/index.html
و این c
http://www.c.happycodings.com/Mathematics/index.html



اینم امتحان کن:

#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
//Begin by defining the functions that are to be called in the main program
double f (double x) //Function 1 Finding 1/x, the integrand, this shall be called f
{ //Function 1 Body
double y;
y=1.0/x;
return y;
} //End of Function 1
double trap (int n, double a, double b) //Function 2 Calculation of the areas of the strips, called trap { double d, h=0, area; d=(b-a)/n; //d=Strip Width, "a" and "b" are the upper and lower bounds of the integral for (int i=1; i<=(n-1); i++) // changed commas to semicolons { y+=(f((a+(i*d)))); //This sums the y values from 1 to (n-1) } area=(d*y) + (d/2.0)*(f(a)+f(b)); //Adds the final part of the trapezium rule to the number returned in the for loop above to complete the area return area; //End of Function 2 }double trap (int n, double a, double b) //Function 2 Calculation of the areas of the strips, called trap
{
double d, h=0, area;
d=(b-a)/n; //d=Strip Width, "a" and "b" are the upper and lower bounds of the <strong class="highlight">integral</strong>
for (int i=1; i<=(n-1); i++) // changed commas to semicolons
{
y+=(f((a+(i*d)))); //This sums the y values from 1 to (n-1)
}
area=(d*y) + (d/2.0)*(f(a)+f(b)); //Adds the final part of the trapezium rule to the number returned in the for loop above to complete the area
return area; //End of Function 2
}
int main() //Beginning of the Main Function
{
double a, b, TrapArea;
int n;
cout<<"This will evaluate the integral of the function f(x)=1/x" <<endl;
cout<<"Please enter a value for the lower bound of the integral"<<endl;
cin>>a; //Value inputted for a
cout<<"Please enter a value for the upper bound"<<endl;
cin>>b; //Value inputted for b
cout<<"Please enter an integer value for the number of strips"<<endl;
cin>>n; //Value inputted for n
TrapArea=trap(n,a,b);
cout<<"The area calculated using the trapezium rule is apporixmately"<<TrapArea<<endl;
}
return 0;
#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
//Begin by defining the functions that are to be called in the main program
double f (double x) //Function 1 Finding 1/x, the integrand, this shall be called f
{ //Function 1 Body
double y;
y=1.0/x;
return y;
} //End of Function 1
double trap (int n, double a, double b) //Function 2 Calculation of the areas of the strips, called trap
{
double d, h=0, area;
d=(b-a)/n; //d=Strip Width, "a" and "b" are the upper and lower bounds of the <strong class="highlight">integral</strong>
for (int i=1, i<=(n-1), i++)
{
y+=(f((a+(i*d)))); //This sums the y values from 1 to (n-1)
}
area=(d*y) + (d/2.0)*(f(a)+f(b)); //Adds the final part of the trapezium rule to the number returned in the for loop above to complete the area
return area; //End of Function 2
}
int main() //Beginning of the Main Function
{
double a, b, TrapArea;
int n;
cout<<"This will evaluate the <strong class="highlight">integral</strong> of the function f(x)=1/x" <<endl;
cout<<"Please enter a value for the lower bound of the integral"<<endl;
cin>>a; //Value inputted for a
cout<<"Please enter a value for the upper bound"<<endl;
cin>>b; //Value inputted for b
cout<<"Please enter an integer value for the number of strips"<<endl;
cin>>n; //Value inputted for n
TrapArea=trap(n,a,b);
cout<<"The area calculated using the trapezium rule is apporixmately"<<TrapArea<<endl;
}
return 0;

xxxxx_xxxxx
دوشنبه 05 مرداد 1388, 20:19 عصر
فكر مي كنم براي مشتق اگر قوانين مشتق رو كنار بزاريم و از تعريف اون استفاده كنيم بهتر باشه. اينطوري جامع تر هست. ولي مشكل تر.

تعريف مشتق در ضميمه