473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

A simple program with Monte Carlo

Can someone understand my errors in this program? in particular the
reason cos i receive the worning message.
/* Questo programma riguarda il calcolo del mutuo accoppiamento fra
patch dell'array. */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_monte.h>
#include <gsl/gsl_monte_vegas.h>

#define IMPEDENZA_ONDA_SPAZIO_LIBERO 120*M_PI

double calcolo_ammettenza_parte_reale (double u_pr[], size_t dimr, void
*p_r);
double calcolo_ammettenza_parte_immag (double u_pc[], size_t dimc, void
*p_c);

int main ()
{
const double K_0 = 2*M_PI*10e9/3e8 ;
struct param_integrale { double a ; double b ; double c ; double f
; } parametri_slot = { K_0*1.186e-2, K_0*0.081e-2, K_0*(0.906 + 0.081),
K_0*0} ;
double res_reale, err_reale, res_immag, err_immag ;
double x_l[2] = {}, x_u[2] ; /* Ricordarsi di inizializzarli. */
const gsl_rng_type *T ;
gsl_rng *r ;
size_t calls = 100000 ;
gsl_monte_function ammettenza_reale =
{&calcolo_ammettenza_parte_reale, 2, &parametri_slot} ,
ammettenza_immag =
{&calcolo_ammettenza_parte_immag, 2, &parametri_slot} ;

gsl_rng_setup () ;
T = gsl_rng_default ;
r = gsl_rng_alloc (T) ;
gsl_monte_vegas_state *s = gsl_monte_vegas_alloc (2) ;

do {
gsl_monte_vegas_integrate (&ammettenza_reale, x_l, x_u, 2,
calls, r, s, &res_reale, &err_reale) ;
} while (fabs (s->chisq - 1.0) > 0.5) ;
printf ("risultato = %.6f, sigma = %.6f, chisq/dof = %.1f\n",
res_reale, err_reale, s->chisq) ;

do {
gsl_monte_vegas_integrate (&ammettenza_immag, x_l, x_u, 2,
calls, r, s, &res_immag, &err_immag) ;
} while (fabs (s->chisq - 1.0) > 0.5) ;
printf ("risultato = %.6f, sigma = %.6f, chisq/dof = %.1f\n",
res_immag, err_immag, s->chisq) ;

return 0;
}

double calcolo_ammettenza_parte_reale (double u_pr[], size_t dimr, void
*p_r)
{
/* p è un puntatore generico che qui punta ad una struttura. */
struct param_integrale *p_slotr = (struct param_integrale *) p_r;
double primo_addendo, secondo_addendo, primo_molt, secondo_molt;

primo_addendo = ((pow (u_pr[0], 2)/2 - pow (u_pr[1], 2))* cos (sqrt
(pow(u_pr[0], 2)) + pow(u_pr[1], 2))) / pow (pow(u_pr[0], 2) +
pow(u_pr[1], 2), 2);
secondo_addendo = ((pow (u_pr[0], 2)/2) - pow (u_pr[0], 2)/(2*(pow
(u_pr[0], 2) + pow (u_pr[1], 2))) + pow (u_pr[1], 2)/( pow(u_pr[0], 2)
+ pow (u_pr[1], 2)) * sin (sqrt (pow(u_pr[0], 2)) + pow(u_pr[1], 2))) /
pow ( pow (u_pr[0], 2) + pow (u_pr[1], 2), 3/2);
primo_molt = p_slotr.b - fabs (u_pr[0] + p_slotr.c);
secondo_molt = p_slotr.a - fabs (u_pr[1] + p_slotr.f);

return (primo_addendo + secondo_addendo) * primo_molt *
secondo_molt;
}

double calcolo_ammettenza_parte_immag (double u_pc[], size_t dimd, void
*p_c)
{
/* p è un puntatore generico che qui punta ad una struttura. */
struct param_integrale *p_slotc = (struct param_integrale *) p_c;
double pr_addendo, sec_addendo, pr_molt, sec_molt;

pr_addendo = ((pow (u_pc[0], 2)/2) - pow (u_pc[0], 2)/(2*(pow
(u_pc[0], 2) + pow (u_pc[1], 2))) + pow (u_pc[1], 2)/( pow(u_pc[0], 2)
+ pow (u_pc[1], 2)) * cos (sqrt (pow(u_pc[0], 2)) + pow(u_pc[1], 2))) /
pow ( pow (u_pc[0], 2) + pow (u_pc[1], 2), 3/2);
sec_addendo = ((pow (u_pc[0], 2)/2 - pow (u_pc[1], 2))* sin (sqrt
(pow(u_pc[0], 2)) + pow(u_pc[1], 2))) / pow (pow(u_pc[0], 2) +
pow(u_pc[1], 2), 2);
pr_molt = p_slotc.b - fabs (u_pc[0] + p_slotc.c);
sec_molt = p_slotc.a - fabs (u_pc[1] + p_slotc.f);

return (pr_addendo + sec_addendo) * pr_molt * sec_molt;
}

The output at shell is:

marco@scatola:~$ gcc mutuoaccoppiamento.c -lgsl -lgslcblas -Wall -lm
mutuoaccoppiamento.c: In function `main':
mutuoaccoppiamento.c:27: warning: implicit declaration of function
`gsl_rng_setup'
mutuoaccoppiamento.c: In function `calcolo_ammettenza_parte_reale':
mutuoaccoppiamento.c:53: error: request for member `b' in something not
a structure or union
mutuoaccoppiamento.c:53: error: request for member `c' in something not
a structure or union
mutuoaccoppiamento.c:54: error: request for member `a' in something not
a structure or union
mutuoaccoppiamento.c:54: error: request for member `f' in something not
a structure or union
mutuoaccoppiamento.c: In function `calcolo_ammettenza_parte_immag':
mutuoaccoppiamento.c:67: error: request for member `b' in something not
a structure or union
mutuoaccoppiamento.c:67: error: request for member `c' in something not
a structure or union
mutuoaccoppiamento.c:68: error: request for member `a' in something not
a structure or union
mutuoaccoppiamento.c:68: error: request for member `f' in something not
a structure or union

I hope someone can help me.

Dec 4 '05 #1
3 1634
On 4 Dec 2005 06:52:33 -0800, in comp.lang.c , "Aleramo"
<mo************@yahoo.it> wrote:
int main ()
{
const double K_0 = 2*M_PI*10e9/3e8 ;
struct param_integrale { double a ; double b ; double c ; double f
; } parametri_slot = { K_0*1.186e-2, K_0*0.081e-2, K_0*(0.906 + 0.081),
this struct definition is local to main(). The definition isn't
visible ouside main(), so that....
double calcolo_ammettenza_parte_reale (double u_pr[], size_t dimr, void
*p_r)
{
/* p è un puntatore generico che qui punta ad una struttura. */
struct param_integrale *p_slotr = (struct param_integrale *) p_r;
.... this function cannot see the struct definition, and you get an
error.
Move the structure definition ouside main(), and just create and
initialise the variable in main.
secondo_molt = p_slotr.a - fabs (u_pr[1] + p_slotr.f);
Also, you'll find you need -> not . here, since p_slotr is a pointer
to the struct.

Lastly... double x_l[2] = {}, x_u[2] ; /* Ricordarsi di inizializzarli. */


you can't do that - there has to be a value in the braces.

Please turn up compiler warning levels to the maximum, and try with a
simpler programme first.
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 4 '05 #2
Thank u for everithing Mark!!! u are very clever!!!
I am Marco and i come from Italy and u?
double x_l[2] = {}, x_u[2] ; /* Ricordarsi di inizializzarli. */
I think u don't know my lenguage cos "/* Ricordarsi di inizializzarli.
*/" means: "U remember to inizialaze it".
I thought the symbols "->" and "." was equivalent but u showed me i
wrong.
Bye bye.

Dec 4 '05 #3
On 4 Dec 2005 09:23:34 -0800, in comp.lang.c , "Aleramo"
<mo************@yahoo.it> wrote:

double x_l[2] = {}, x_u[2] ; /* Ricordarsi di inizializzarli. */
I think u don't know my lenguage cos "/* Ricordarsi di inizializzarli.
*/" means: "U remember to inizialaze it".


Actually I read italian, but the point is, your code didn't compile.

You should always post the actual code you wrote, so that you do not
make different typing mistakes which mislead people trying to help you
..

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 4 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: mescaline | last post by:
hi, i'm new to C++ could anyone refer me to a good site / good examples of random numbers? in particular including: 1) the commnds to obtain normally and exponenetially distributed r...
13
by: mgorbach | last post by:
Im writing a program that does monte carlo simulation and im having trouble figuring out how to get the threading model right. I have a simulation class which contains all simulation data and...
3
by: Mark Kamoski | last post by:
Hi-- Please help. How can one implement a simple site search for an ASP.NET site that consists of ASPX and ASCX content pages? I have a small site (of less than 100 content pages). The...
1
by: Carlo B | last post by:
I need the program to compare two numbers and although the code below works I have a feeling that it can be done in fewer lines. Is there a better way? Dim first, second, third, var As Integer...
0
by: opticyclic | last post by:
Does anyone have any examples of a monte carlo implementation using VB.NET? I'm trying to model the effect of small changes of x in y where y is a function of x.
15
by: ianweise | last post by:
hello, before i post my code for this, is there anyone out there at this moment? no sense in posting if no one is out there to read and answer it =P
176
by: nw | last post by:
Hi, I previously asked for suggestions on teaching testing in C++. Based on some of the replies I received I decided that best way to proceed would be to teach the students how they might write...
20
by: cmbcorp | last post by:
Hi, I have been playing around with a simple php login script and im getting an error message when i attempt to log in with the username and password i set in the sql table. The error message is...
26
by: Prime Mover | last post by:
Hello all, I have got the pseudo-code below that I would like to convert to c language. The algorithm calculates Pi value. I am somewhat familiar with C language, but I am just starting to learn...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.