![]() |
1. Пользуйтесь тегами кода. - [code] ... [/code]
2. Точно указывайте язык, название и версию компилятора (интерпретатора).
3. Название темы должно быть информативным.
В описании темы указываем язык!!!
![]() ![]() |
![]() |
So Slow |
![]() ![]()
Сообщение
#1
|
Новичок ![]() Группа: Пользователи Сообщений: 21 Пол: Мужской Реальное имя: Stas Репутация: ![]() ![]() ![]() |
у кого-нибуть есть метод Лобачевского нахождения корней многочлена?
я нашёл метод методе Лобачевского-Греффе (ну эт практически одно и тоже), но эта прога на каком-то другом языке(фортран вродеб), и там ничего не понятно.
кто разбераеться переделайте под паскаль ПЛЗ. ЗЫ если есть на С++, то тож пойдет Сообщение отредактировано: So Slow - 20.05.2007 6:47 |
volvo |
![]()
Сообщение
#2
|
Гость ![]() |
Есть исходник метода Лобачевского, С++ (С) Johna Smith, 1996
Поскольку раздел Паскалевский - см. приват... Update Поскольку тема перенесена в соотв. раздел - вот исходник:
//////////////////////////////////////////////////////////////////////////////
// Solving nonlinear equations (Lobachevsky method)
// (c) Johna Smith, 1996
//
// Method description:
// Given: a0+a1x+a2x^2+...+anx^n=0
// This method allows to find modulus of the greatest root of this equation
// even if it's complex. But in last case there can appear several messages
// about impossibilty of calculation root of negative number.
// The main idea of this method is to change given equation to other
// equation which roots equals to powered roots of given equation. For example
// if roots of the given equation are x0,x1,.. xn then roots of new equation
// will be x0^2, x1^2, ..., xn^2. Repeating this operation we get an equation
// where one root is much greater than other ones. So we can easily
// obtain modulus of the greatrest root of the given equation.
// To obtain other roots of equation we need to divide given equation
// by (x-x0) (where x0 is found root) and apply this method to result.
//
//////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <math.h>
#define N 4
#define N1 N+1
#define Iterations 15 // number of iterations
double a[N1]={24,-50,35,-10,1};
void main(void)
{
double r,b[N1],c[N1],g,bi,d;
int z,k;
// printing given equation
printf("%f",a[0]);
for(int i=1;i<N1;i++) printf("%+fx^%d",a[i],i);
printf("=0\n\n");
// preparing auxiliary arrays b and c
for (i=0;i<N1;i++)
{
b[i]=a[i]/a[N];
c[i]=0;
}
// setting required parameters
r=1/2.0;
g=1;
// make all iterations
for(int y=0;y<Iterations;y++)
{
// calculate coefficients c[i] (coefficients of new equation)
z=1;
for(i=0;i<N1;i++)
{
bi=z*b[i];
k=(i+1)/2;
for(int j=i%2;j<N1;j+=2)
{
c[k]+=bi*b[j];
k++;
}
z=-z;
}
d=z*c[N-1];
// check whether we could calculate root of d
if(d>0)
{
// calculating and printing new iteration
g*=powl(d,r);
printf("%f\n",g);
for (i=0;i<N1;i++)
{
// preparing data for next iteration
b[i]=c[i]/powl(d,N-i);
c[i]=0;
}
b[N-1]=z;
b[N]=-z;
} else
{
// d is negative - can't calculate root
for(i=0;i<N1;i++)
{
// preparing data for next iteration
b[i]=c[i];
c[i]=0;
}
printf("no iteration (can't calculate root from negative number)\n");
}
r/=2.0;
}
}
Сообщение отредактировано: volvo - 20.05.2007 12:00 |
So Slow |
![]()
Сообщение
#3
|
Новичок ![]() Группа: Пользователи Сообщений: 21 Пол: Мужской Реальное имя: Stas Репутация: ![]() ![]() ![]() |
cпрога хорошая, но вот если корни комплексные, то уже не счетает(, а мене над чтоб комплексные тоже счетал
|
volvo |
![]()
Сообщение
#4
|
Гость ![]() |
А об этом надо было сразу говорить... Посмотрю, что можно сделать...
|
![]() ![]() |
![]() |
Текстовая версия | 31.07.2025 4:19 |