DOS.
1 . , b=i+j, a=2,
x= i j+3/i
2 .
3 . Z =
4 Y= +
n | n | n>0 | ||
1. 2. X 3. . . Y 4. . | . . . . | A = {aij} X = {xi} Y Rez | a[i][j] x[i] y rmo | |
1. 2. 3. , . 4. 5. 1/X 7. 8. 1/D - 9. . 10. . 11. | . . . . . . . . . | i j A2 = {aij} A = {aij} nv= {nvij} x D= {Di} a b razn= {raznij} | i j a2[i][j] At[i][j] nv[i][j] x d[i] a b razn[i][j] | 1,2,...n 1,2,n 0 1 |
. n =
X .
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
//-------------------------------------------------
typedef struct{
unsigned cl:4;
unsigned fon:3;
unsigned bl:1;
} Att;
//-------------------------------------------------
typedef union{
unsigned char cod;
Att att;
} Mix;
//-------------------------------------------------
Mix set_attr(int b,int fon,int col)
{
Mix a1;
a1.att.bl=b;a1.att.fon=fon;a1.att.cl=col;
return a1;
}
//-------------------------------------------------
typedef double (*fun)(double x);
//-------------------------------------------------
double prlog(double x)
{
return 1/(x*log(3));
}
//-------------------------------------------------
double log3(double x)
{
return log(x)/log(3);
}
//-------------------------------------------------
double logy(double x)
{
return log(3)/x;
}
//-------------------------------------------------
|
|
fun Tab_fun[2][2]={{&log3,&prlog},{&log, &log}};
fun Tab_integ[2][2]={{&log,&logy},{&cos,&sin}};
//-------------------------------------------------
double Integ(fun ff,double a, double b)
{
fun f1;int i;
for(i=0;i<2;i++)
if(Tab_integ[i][0]==ff)
f1=Tab_integ[i][1];
return((*f1)(b)-(*f1)(a));
}
//-------------------------------------------------
double Dif_fun(fun ff, double x)
{
fun f1;int i,j;
for(i=0;i<2;i++)if(Tab_fun[i][0]==ff)
f1=Tab_fun[i][1];
return (*f1)(x);
}
//-------------------------------------------------
void form_matr(double **a, int n){
int i, j;
for (i = 1.0; i <= n; i++){
for (j = 1.0; j <= n; j++)
a[i-1][j-1]=tan(M_PI*(8.25+double(i+j)/2.0))*Dif_fun(log3,double(i*j)+3.0/double(i))+Integ(cos,2.0,double(i+j));
}
}
//-------------------------------------------------
void form_vect(double *x, double **a, int n)
{
for(int i=0;i<n;i++)
{
x[i]=-10e20;
for(int j=0;j<n;j++)
{
if(a[j][i]<0)
{
if(a[j][i]>x[i])
x[i]=a[j][i];
}
}
}
}
//-------------------------------------------------
void print_matr(double **a, int n, FILE *F)
{
int i, j;
for(i = 0; i < n; i++)
{
for(j = 0; j < n; j++)
{
fprintf(F, "%10.5f ",a[i][j]);
}
fprintf(F, "\n");
}
}
//-------------------------------------------------
void print_vect(double *x, int n, FILE *F)
{
int i;
Mix A1;
A1=set_attr(0,RED,YELLOW);
textattr(A1.cod);
for (i = 0; i < n; i++)
{
fprintf(F, "%10.5f ", x[i]);
}
for (i = 0; i < n; i++)
{
cprintf("%10.5f ", x[i]);
}
printf("\n");
}
//-------------------------------------------------
void Transpon(double **At, double **a, int n){
int i, j;
for (i = 0; i < n; i++){
for (j = 0; j < n; j++)
At[i][j] = a[j][i];
}
}
//-------------------------------------------------
void sqrM(double **a2, double **a, int n){
int i,j,k;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
a2[i][j] = 0.0;
for (k = 0; k < n; k++)
a2[i][j] += a[i][k] * a[k][j];
}
}
}
//-------------------------------------------------
void razn_matr(double **a1, double **a2, double **razn, int n) {
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
razn[i][j] = a1[i][j] - a2[i][j];
}
//-------------------------------------------------
void umnozh_vm(double **a,double *v,double *nv,int n)
{
double s;
for(int i=0;i<n;i++)
{ s=0;
for(int j=0;j<n;j++)
s=s+v[j]*a[i][j];
nv[i]=s;
}
}
//-------------------------------------------------
double umnozh_sst(double *str,double *stl,int n)
{
double c;
for(int i=0;i<n;i++)
c=c+str[i]*stl[i];
return c;
}
//-------------------------------------------------
double **GetMemoryMatr(int n)
{
int i;
double **a;
a = (double **)malloc(n*sizeof(double *));
for (i = 0; i < n; i++)
a[i] = (double *)malloc(n*sizeof(double));
return a;
}
//-------------------------------------------------
void FreeMemoryMatr(double **a, int n)
{
int i;
for (i = 0; i < n; i++)
free(a[i]);
free(a);
}
//-------------------------------------------------
double *GetMemoryVect(int n){
double *v;
|
|
v = (double *)malloc(n*sizeof(double));
return v;
}
//-------------------------------------------------
int Fact(int x)
{
int s=1;
for(int i=1;i<=x;i++)
s=s*i;
return s;
}
//-------------------------------------------------
void FreeMemVect(double *v)
{
free(v);
}
//-------------------------------------------------
double GetY(double **a,double *x,int n)
{
double min,p1,p2,c;
int i,k;
for (i=0;i<n;i++)
{
min=10e19;
c=1;
for(k=i+1;k=0;k--)
{
if (a[i][k-1]<0)
c=c*a[i][k-1];
}
if(c==1) c=0;
if(c<min)
min=c;
}
p1=min;
double S=0;
for(k=1;k<n;k+=2)
{
S=S+pow(x[k],Fact(k+1)/(k+1));
}
p2=S;
printf("%f %f",p1,p2);
return p1+p2;
}
//-------------------------------------------------
void Get1X(double *x, double *x1, int n)
{
for(int i=0;i<n;i++)
x1[i]=1.0/x[i];
}
//-------------------------------------------------
void GetD(double **a,double *d, int n)
{
for(int i=0;i<n;i++)
d[i]=1.0/a[i][i];
}
//-------------------------------------------------
void main()
{
clrscr();
double **a,**razn,*x,*x1,**a2,**At,rmo,*d,*nv;
FILE *fo=fopen("d:/res.txt", "w");;
int n;
printf(" n=");
scanf("%d",&n);
a=GetMemoryMatr(n);razn=GetMemoryMatr(n);
a2=GetMemoryMatr(n);At=GetMemoryMatr(n);
nv=GetMemoryVect(n);x=GetMemoryVect(n);x1=GetMemoryVect(n);
d=GetMemoryVect(n);d=GetMemoryVect(n);
fprintf(fo," :\n\n");
form_matr(a,n);
print_matr(a,n,fo);
//Part II
fprintf(fo,"\n X:\n\n");
form_vect(x,a,n);
print_vect(x,n,fo);
Get1X(x,x1,n);
fprintf(fo,"\n\n1/X:\n\n");
print_vect(x1,n,fo);
GetD(a,d,n);
fprintf(fo,"\n\n 1/D:\n\n");
print_vect(d,n,fo);
//Part III
Transpon(At,a,n);
fprintf(fo,"\n\n : A\n");
print_matr(At,n,fo);
razn_matr(At,a,razn,n);
fprintf(fo,"\n\n . :\n\n");
print_matr(razn,n,fo);
sqrM(a2,razn,n);
fprintf(fo,"\n :\n\n");
print_matr(a2,n,fo);
umnozh_vm(a2,x1,nv,n);
fprintf(fo,"\n 1/X 2:\n\n");
print_vect(nv,n,fo);
rmo=umnozh_sst(nv,d,n);
fprintf(fo,"\n\n (): %f\n\n", rmo);
double Y=GetY(a,x,n);
fprintf(fo,"\n\n :\n\nY = %f",Y);
FreeMemoryMatr(a,n);FreeMemoryMatr(razn,n);
FreeMemoryMatr(a2,n);FreeMemoryMatr(At,n);
FreeMemVect(x);FreeMemVect(x1);
FreeMemVect(nv);FreeMemVect(d);
getchar();getchar();
fcloseall();
}
MathCad.
,
, n=2:
:
0.22756 -0.95023
-1.02825 -1.50060
X:
-1.02825 -0.95023
1/X:
-0.97253 -1.05238
1/D:
4.39445 -0.66640
: A
0.22756 -1.02825
-0.95023 -1.50060
. :
0.00000 -0.07802
0.07802 0.00000
:
-0.00609 0.00000
0.00000 -0.00609
1/X 2:
0.00592 0.00641
(): 0.021746
:
Y = -0.950225
, , .
: , .
|
|