11/01/2019, 19:03
double y = funzione( x, c, r0 );
struct Retta {
double m;
double q;
};
{
retta->m = c;
retta->q = r * sin( c * c + 1 );
}
11/01/2019, 23:29
c
e gli x
durante il ciclo, ma è senz'altro possibile farlo. Per esempio:#include <math.h>
#include <stdio.h>
/**
* Data la famiglia di rette
* \[\{ f_{c,\ r} = cx + r\sin(c^2 + 1) \colon c, r \in \mathbf{R} \},\]
* questa funzione calcola il valore della funzione $f_{c,r}$ nel punto $x$.
*/
double funzione(double x, double c, double r);
int main(void)
{
#define NUM_RETTE (5)
double c[NUM_RETTE];
#define NUM_SEGMENTI (10)
double x[NUM_SEGMENTI];
double y[NUM_RETTE][NUM_SEGMENTI];
const double r0 = 2.0;
/* inizializzazione c */
c[0] = 0.1;
{
int i;
for (i = 1; i < NUM_RETTE; ++i)
{
c[i] = c[i - 1] + 0.1;
}
}
/* inizializzazione x */
x[0] = 0.0;
{
int i;
const double d = 1.0 / NUM_SEGMENTI;
for (i = 1; i < NUM_SEGMENTI; ++i)
{
x[i] = x[i - 1] + d;
}
}
{ /* calcolo delle y */
int i;
for (i = 0; i < NUM_RETTE; ++i)
{
int j;
for (j = 0; j < NUM_SEGMENTI; ++j)
{
y[i][j] = funzione(x[j], c[i], r0);
}
}
}
{ /* stampare a video */
int i;
for (i = 0; i < NUM_RETTE; ++i)
{
int j;
for (j = 0; j < NUM_SEGMENTI; ++j)
{
printf("c=%f, r=%f, x=%f, y=%f\n", c[i], r0, x[j], y[i][j]);
}
}
}
#undef NUM_RETTE
#undef NUM_SEGMENTI
}
double funzione(double x, double c, double r)
{
return x * c + r * sin(c * c + 1);
}
#include <math.h>
#include <stdio.h>
/**
* Data la famiglia di rette
* \[\{ f_{c,\ r} = cx + r\sin(c^2 + 1) \colon c, r \in \mathbf{R} \},\]
* questa funzione calcola il valore della funzione $f_{c,r}$ nel punto $x$.
*/
double funzione(double x, double c, double r);
int main(void)
{
#define NUM_RETTE (5)
double c[NUM_RETTE] = { [0] = 0.1 };
for (int i = 1; i < NUM_RETTE; ++i)
{
c[i] = c[i - 1] + 0.1;
}
#define NUM_SEGMENTI (10)
double x[NUM_SEGMENTI] = { [0] = 0.0 };
{
const double d = 1.0 / NUM_SEGMENTI;
for (int i = 1; i < NUM_SEGMENTI; ++i)
{
x[i] = x[i - 1] + d;
}
}
double y[NUM_RETTE][NUM_SEGMENTI];
const double r0 = 2.0f;
// calcolo delle y
for (int i = 0; i < NUM_RETTE; ++i)
{
for (int j = 0; j < NUM_SEGMENTI; ++j)
{
y[i][j] = funzione(x[j], c[i], r0);
}
}
// stampare a video
for (int i = 0; i < NUM_RETTE; ++i)
{
for (int j = 0; j < NUM_SEGMENTI; ++j)
{
printf("c=%f, r=%f, x=%f, y=%f\n", c[i], r0, x[j], y[i][j]);
}
}
#undef NUM_SEGMENTI
#undef NUM_RETTE
}
double funzione(double x, double c, double r)
{
return x * c + r * sin(c * c + 1);
}
#include <math.h>
#include <stdio.h>
/**
* Data la famiglia di rette
* \[\{ f_{c,\ r} = cx + r\sin(c^2 + 1) \colon c, r \in \mathbf{R} \},\]
* questa funzione calcola il valore della funzione $f_{c,r}$ nel punto $x$.
*/
double funzione(double x, double c, double r);
/**
* Inizializza un array con una progressione aritmentica
*/
void inizializza(double a[], unsigned int size, double start, double step);
int main(void)
{
#define NUM_RETTE (5)
double c[NUM_RETTE];
inizializza(c, NUM_RETTE, 0.1, 0.1);
#define NUM_SEGMENTI (10)
double x[NUM_SEGMENTI];
inizializza(x, NUM_SEGMENTI, 0.0, (1.0 / NUM_SEGMENTI));
double y[NUM_RETTE][NUM_SEGMENTI];
const double r0 = 2.0;
for (int i = 0; i < NUM_RETTE; ++i)
{
for (int j = 0; j < NUM_SEGMENTI; ++j)
{
y[i][j] = funzione(x[j], c[i], r0);
}
}
for (int i = 0; i < NUM_RETTE; ++i)
{
for (int j = 0; j < NUM_SEGMENTI; ++j)
{
printf("c=%f, r=%f, x=%f, y=%f\n", c[i], r0, x[j], y[i][j]);
}
}
#undef NUM_RETTE
#undef NUM_SEGMENTI
}
double funzione(double x, double c, double r)
{
return x * c + r * sin(c * c + 1);
}
void inizializza(double a[], unsigned int size, double start, double step)
{
a[0] = start;
for (unsigned int i = 1; i < size; ++i)
{
a[i] = a[i - 1] + step;
}
}
12/01/2019, 00:43
/* inizializzazione x */
x[0] = 0.0;
{
int i;
const double d = 1.0 / NUM_SEGMENTI;
for (i = 1; i < NUM_SEGMENTI; ++i)
{
x[i] = x[i - 1] + d;
}
}
y[i][j] = funzione(x[j], c[i], r0);
}
#undef NUM_RETTE
#undef NUM_SEGMENTI
}
12/01/2019, 17:12
#undef
serve ad annullare un #define
. La puoi ignorare.for( i = 0; i < 3; i++ )
printf( "1" );
printf( "2" );
for( i = 0; i < 3; i++ )
{
printf( "1" );
printf( "2" ):
}
13/01/2019, 19:34
for( i = 0; i < 3; i++ ){
printf( "1" ); }
printf( "2" );
for( i = 0; i < 3; i++ )
{
printf( "1" );
printf( "2" ):
}
{
int i;
const double d = 1.0 / NUM_SEGMENTI;
for (i = 1; i < NUM_SEGMENTI; ++i)
{
x[i] = x[i - 1] + d;
}
for( i = 0; i < 3; i++ )
printf( "1" );
printf( "2" );
14/01/2019, 16:25
int main( void )
{
{ int i; }
i = 2;
}
i
i
al solo ciclo.14/01/2019, 20:45
Skuola.net News è una testata giornalistica iscritta al Registro degli Operatori della Comunicazione.
Registrazione: n° 20792 del 23/12/2010.
©2000—
Skuola Network s.r.l. Tutti i diritti riservati. — P.I. 10404470014.
Powered by phpBB © phpBB Group - Privacy policy - Cookie privacy
phpBB Mobile / SEO by Artodia.