الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

محتاج مساعده

مغلق
بدأه tatsoft في 4 مايو 2007 · 3 رد · 460 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

اخواني اذا فيه واحد يقدر يساعدني في تصميم برامج (دوال ) لحل بعض طرق التحليل العددي command line applications

حاليا انا سويت طريقتين(برنامجين )

الرجاء الرد

و شكرا

#2
اقتباس
حاليا انا سويت طريقتين(برنامجين )

ضع اللي سويته لكي نرى ما توصلت له !

وحاول ان تضع عنوان مناسب لموضوعك ؟... لكي تجد التفاعل

راجع قواعد المشاركة من هنا

تم تعديل هذه المشاركة بواسطة HnHn في 4 مايو 2007 في 14:29

سجل ايميلك هنا

googlejb5.gif ليصلك كل ما هو مفيد في عالم البرمجة
#3

الطريقة الاولى

Newton's Divided Difference Interpolation

double NewtonInterpolation(const double xa[], const double ya[], const double x, const int n)

{

double *f = new double[n];

double *t = new double[n];

for(int i=0; i<n; i++)

{

t = ya;

}

double y = ya[0];

for(int i=0; i<n; i++)

{

f = t[0];

cout << "t: ";

for(int j=0; j<n-i-1; j++)

{

DP deltaX = xa[i+j+1] - xa[j] ;

if (abs(deltaX) < DP_epsilon )

{

y = 0;

cout << "[Error], independent values must be distinct!" << endl;

return 0;

}

t[j] = ( t[j+1] - t[j] ) / deltaX;

cout << t[j] << "\t";

}

cout << endl;

}

for( int i=0; i<n; i++ )

cout << f << "\t";

cout << endl;

DP deltaXs = 1.0;

for( int i=1; i<n; i++)

{

for( int j=0; j<i; j++ )

deltaXs *= x-xa[j];

y += deltaXs*f;

deltaXs = 1.0;

}

delete []f; f = NULL;

delete []t; t = NULL;

return y;

}

void main(){

const double xa[] = {0,2,4,7,1,19,89,8};

const double ya[] = {2,1,1,9,3,4,5,3};

//const DP x = atof(argv[1]);

const double x = 10.0;

double y = Newton(xa, ya, x, 8);

cout << y << endl;

}

الطريقة الثانية

Lagrange method

# include<conio.h>

void main()

{int i,j,n;

float L[9],sum,xp,x[9],y[9],C,D;

sum=0;

printf("Enter n value\n ");

scanf("%d",&n);

printf("\n Enter x and y \n ");

for(i=0;i<n;i++)

scanf("%f %f",&x,&y);

printf("\n Enter point of x ");

scanf("%f",&xp);

clrscr();

printf("Lagrange method\n\n");

printf("\n x ");

for(i=0;i<n;i++) printf("%4.2f\t",x);

printf("\n y ");

for(i=0;i<n;i++) printf("%4.2f\t",y);

printf(" xp= %4.2f\n",xp);

printf\ـــــــــــــــــــــــــــــــــ")

n");

for(i=0;i<n;i++)

{ C=1; D=1;

for(j=0;j<n;j++)

{ if(i!=j) {

C=C*(xp-x[j]) ;

D=D*(x-x[j]);

} }

L=C/D;

sum=sum+L*y;

printf("\n L(%d)= %f ",i,L);

}

printf("\n\ــــــــــــــــــــــــــــــ

n");

printf("\nL=L1*y1+l2*y2+....\n");

printf\ــــــــــــــــــــــــــــــ")

n\n");

printf("L= %f ",sum);

}

#4

إعادة تنسيقها

لطريقة الاولى
Newton's Divided Difference Interpolation


double NewtonInterpolation(const double xa[], const double ya[], const double x, const int n)
{

double *f = new double[n];
double *t = new double[n];

for(int i=0; i<n; i++)
{
t = ya;
}


double y = ya[0];
for(int i=0; i<n; i++)
{
f = t[0];
cout << "t: ";
for(int j=0; j<n-i-1; j++)
{
DP deltaX = xa[i+j+1] - xa[j];
if (abs(deltaX) < DP_epsilon )
{
y = 0;
cout << "[Error], independent values must be distinct!" << endl;
return 0;
}
t[j] = ( t[j+1] - t[j] ) / deltaX;
cout << t[j] << "\t";
}
cout << endl;
}

for( int i=0; i<n; i++ )
cout << f << "\t";
cout << endl;


DP deltaXs = 1.0;
for( int i=1; i<n; i++)
{
for( int j=0; j<i; j++ )
deltaXs *= x-xa[j];
y += deltaXs*f;
deltaXs = 1.0;
}

delete []f; f = NULL;
delete []t; t = NULL;
return y;
}

void main(){

const double xa[] = {0,2,4,7,1,19,89,8};
const double ya[] = {2,1,1,9,3,4,5,3};

//const DP x = atof(argv[1]);
const double x = 10.0;
double y = Newton(xa, ya, x, 8);
cout << y << endl;
}

الطريقة الثانية
Lagrange method

# include<conio.h>
void main()
{int i,j,n;
float L[9],sum,xp,x[9],y[9],C,D;
sum=0;
printf("Enter n value\n ");
scanf("%d",&n);
printf("\n Enter x and y \n ");
for(i=0;i<n;i++)
scanf("%f %f",&x,&y);
printf("\n Enter point of x ");
scanf("%f",&xp);
clrscr();
printf("Lagrange method\n\n");
printf("\n x ");
for(i=0;i<n;i++) printf("%4.2f\t",x);
printf("\n y ");
for(i=0;i<n;i++) printf("%4.2f\t",y);
printf(" xp= %4.2f\n",xp);
printf\ـــــــــــــــــــــــــــــــــ")
n");
for(i=0;i<n;i++)
{ C=1; D=1;
for(j=0;j<n;j++)
{ if(i!=j) {
C=C*(xp-x[j]);
D=D*(x-x[j]);
} }
L=C/D;
sum=sum+L*y;
printf("\n L(%d)= %f ",i,L);
}
printf("\n\ــــــــــــــــــــــــــــــ
n");
printf("\nL=L1*y1+l2*y2+....\n");
printf\ــــــــــــــــــــــــــــــ")
n\n");
printf("L= %f ",sum);
}

تم تعديل هذه المشاركة بواسطة b.m.s في 7 مايو 2007 في 05:25

هذا الموضوع مغلق.

مواضيع مشابهة