473,799 Members | 2,746 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

the trouble with mex c

Hi,

sorry if this message gets posted twice, i seem to have some problem posting
to newsgroups.

i've rewritten some loop in matlab using the mex interface method in c, and
i've achieved a reduction in calculation time of about five hours :).
however, the resulting arrays
are not the same as with matlab. this is the first time i write something in
c, and i suspect i'm making some
mistakes that causes memory regions to be overwritten, pointers to be
misused, that sort of thing that
doesn't make the lcc compiler shipped with matlab complain. i've got no
debugger and after rereading c and
mex documentation i've got no clue what to do. would someone care to take a
glance at the code
and maybe identify some beginners mistake that causes the erroneous results?
I can send the code
as an attachment.

I would greatly appreciate that,

Martijn

Nov 14 '05 #1
13 2122
"Martijn van den Branden" <m.************ *@student.tudel ft.nl> wrote in
message news:bv******** **@news.tudelft .nl...
Hi, <snip> would someone care to take a glance at the code
and maybe identify some beginners mistake that causes the erroneous results? I can send the code
as an attachment.


Don't send in an attachment, trim it down to a reasonable size (no more than
a few KB, but take care not to cut out the bits that show the problem) and
post it here.

Peter
Nov 14 '05 #2
I've included the full code below, but at places i've deleted declarations
of variables
where they are obvious replaced by ...

Thanks in advance,

Martijn

_______________ _______________ _______________ _______________ _______________ _
#include "mex.h"
#include <math.h>
#define PI 3.14159

void source (double x, double y, double z, double x1, double y1, double z1,
double x2, double y2, double z2, double x3, double y3, double
z3,
double x4, double y4, double z4, double *srcphi, double
*dblphi)
{

ALL DECLARATIONS OF THE LOCAL VARIABLES IN THE
EQUATIONS BELOW GO HERE.

*(srcphi) = -1.0/(4*PI)*(
(
(((x-x1)*(y2-y1)-(y-y1)*(x2-x1))/d12)*log((r1+r2 +d12)/(r1+r2-d12)) +
(((x-x2)*(y3-y2)-(y-y2)*(x3-x2))/d23)*log((r2+r3 +d23)/(r2+r3-d23)) +
(((x-x3)*(y4-y3)-(y-y3)*(x4-x3))/d34)*log((r3+r4 +d34)/(r3+r4-d34)) +
(((x-x4)*(y1-y4)-(y-y4)*(x1-x4))/d41)*log((r4+r1 +d41)/(r4+r1-d41))
)
+fabs(z)*(
atan((m12*e1-h1)/(z*r1)) - atan((m12*e2-h2)/(z*r2)) +
atan((m23*e2-h2)/(z*r2)) - atan((m23*e3-h3)/(z*r3)) +
atan((m34*e3-h3)/(z*r3)) - atan((m34*e4-h4)/(z*r4)) +
atan((m41*e4-h4)/(z*r4)) - atan((m41*e1-h1)/(z*r1))
)
);

*(dblphi) = -1.0/(4*PI)*(
atan((m12*e1-h1)/(z*r1)) - atan((m12*e2-h2)/(z*r2))
+ atan((m23*e2-h2)/(z*r2)) - atan((m23*e3-h3)/(z*r3))
+ atan((m34*e3-h3)/(z*r3)) - atan((m34*e4-h4)/(z*r4))
+ atan((m41*e4-h4)/(z*r4)) - atan((m41*e1-h1)/(z*r1)));

return;
}


void coefficientmatr ix(int totpanelsf, int totpanelswake, double eps,
double *xcf, double *ycf, double *zcf,
double *x1f, double *y1f, double *z1f,
double *x2f, double *y2f, double *z2f,
...
...
double *xe2wake, double *ye2wake, double
*ze2wake,
double *xe3wake, double *ye3wake, double
*ze3wake,
double *z1wakeqs, double *z2wakeqs, double
*z3wakeqs, double *z4wakeqs,
double *A, double *S, double *E)
{
int i,j,k,count = 0,count2=0;
double xp, yp, zp;
double pcolloc[3], p1[3], p2[3], p3[3], p4[3];
double srcphi, dblphi;

for(i=0;i<totpa nelsf;i++)
{

xp = xcf[i]-nxf[i]*eps;
yp = ycf[i]-nyf[i]*eps;
zp = zcf[i]-nzf[i]*eps;

for (j=0;j<totpanel sf;j++)
{

pcolloc[0] = xe1[j]*(xp-xcf[j])+ye1[j]*(yp-ycf[j])+ze1[j]*(zp-zcf[j]);
pcolloc[1] = xe2[j]*(xp-xcf[j])+ye2[j]*(yp-ycf[j])+ze2[j]*(zp-zcf[j]);
pcolloc[2] = nxf[j]*(xp-xcf[j])+nyf[j]*(yp-ycf[j])+nzf[j]*(zp-zcf[j]);

p1[0] =
xe1[j]*(x1f[j]-xcf[j])+ye1[j]*(y1f[j]-ycf[j])+ze1[j]*(z1fqs[j]-zcf[j]);
p1[1] =
xe2[j]*(x1f[j]-xcf[j])+ye2[j]*(y1f[j]-ycf[j])+ze2[j]*(z1fqs[j]-zcf[j]);
p1[2] =
nxf[j]*(x1f[j]-xcf[j])+nyf[j]*(y1f[j]-ycf[j])+nzf[j]*(z1fqs[j]-zcf[j]);

p2[0] =
xe1[j]*(x2f[j]-xcf[j])+ye1[j]*(y2f[j]-ycf[j])+ze1[j]*(z2fqs[j]-zcf[j]);
p2[1] =
xe2[j]*(x2f[j]-xcf[j])+ye2[j]*(y2f[j]-ycf[j])+ze2[j]*(z2fqs[j]-zcf[j]);
p2[2] =
nxf[j]*(x2f[j]-xcf[j])+nyf[j]*(y2f[j]-ycf[j])+nzf[j]*(z2fqs[j]-zcf[j]);

p3[0] =
xe1[j]*(x3f[j]-xcf[j])+ye1[j]*(y3f[j]-ycf[j])+ze1[j]*(z3fqs[j]-zcf[j]);
p3[1] =
xe2[j]*(x3f[j]-xcf[j])+ye2[j]*(y3f[j]-ycf[j])+ze2[j]*(z3fqs[j]-zcf[j]);
p3[2] =
nxf[j]*(x3f[j]-xcf[j])+nyf[j]*(y3f[j]-ycf[j])+nzf[j]*(z3fqs[j]-zcf[j]);

p4[0] =
xe1[j]*(x4f[j]-xcf[j])+ye1[j]*(y4f[j]-ycf[j])+ze1[j]*(z4fqs[j]-zcf[j]);
p4[1] =
xe2[j]*(x4f[j]-xcf[j])+ye2[j]*(y4f[j]-ycf[j])+ze2[j]*(z4fqs[j]-zcf[j]);
p4[2] =
nxf[j]*(x4f[j]-xcf[j])+nyf[j]*(y4f[j]-ycf[j])+nzf[j]*(z4fqs[j]-zcf[j]);

source(pcolloc[0],pcolloc[1],pcolloc[2],p1[0],p1[1],p1[2],
p2[0],p2[1],p2[2],p3[0],p3[1],p3[2],
p4[0],p4[1],p4[2],&srcphi, &dblphi);

*(S+count)= srcphi;
*(A+count)= dblphi;
count++;
}

for (k=0;k<totpanel swake;k++)
{

pcolloc[0] =
xe1wake[k]*(xp-xcwake[k])+ye1wake[k]*(yp-ycwake[k])+ze1wake[k]*(zp-zcwake[k]
);
pcolloc[1] =
xe2wake[k]*(xp-xcwake[k])+ye2wake[k]*(yp-ycwake[k])+ze2wake[k]*(zp-zcwake[k]
);
pcolloc[2] =
xe3wake[k]*(xp-xcwake[k])+ye3wake[k]*(yp-ycwake[k])+ze3wake[k]*(zp-zcwake[k]
);

p1[0] =
xe1wake[k]*(x1wake[k]-xcwake[k])+ye1wake[k]*(y1wake[k]-ycwake[k])+ze1wake[k]
*(z1wakeqs[k]-zcwake[k]);
p1[1] =
xe2wake[k]*(x1wake[k]-xcwake[k])+ye2wake[k]*(y1wake[k]-ycwake[k])+ze2wake[k]
*(z1wakeqs[k]-zcwake[k]);
p1[2] =
xe3wake[k]*(x1wake[k]-xcwake[k])+ye3wake[k]*(y1wake[k]-ycwake[k])+ze3wake[k]
*(z1wakeqs[k]-zcwake[k]);

p2[0] =
xe1wake[k]*(x2wake[k]-xcwake[k])+ye1wake[k]*(y2wake[k]-ycwake[k])+ze1wake[k]
*(z2wakeqs[k]-zcwake[k]);
p2[1] =
xe2wake[k]*(x2wake[k]-xcwake[k])+ye2wake[k]*(y2wake[k]-ycwake[k])+ze2wake[k]
*(z2wakeqs[k]-zcwake[k]);
p2[2] =
xe3wake[k]*(x2wake[k]-xcwake[k])+ye3wake[k]*(y2wake[k]-ycwake[k])+ze3wake[k]
*(z2wakeqs[k]-zcwake[k]);

p3[0] =
xe1wake[k]*(x3wake[k]-xcwake[k])+ye1wake[k]*(y3wake[k]-ycwake[k])+ze1wake[k]
*(z3wakeqs[k]-zcwake[k]);
p3[1] =
xe2wake[k]*(x3wake[k]-xcwake[k])+ye2wake[k]*(y3wake[k]-ycwake[k])+ze2wake[k]
*(z3wakeqs[k]-zcwake[k]);
p3[2] =
xe3wake[k]*(x3wake[k]-xcwake[k])+ye3wake[k]*(y3wake[k]-ycwake[k])+ze3wake[k]
*(z3wakeqs[k]-zcwake[k]);

p4[0] =
xe1wake[k]*(x4wake[k]-xcwake[k])+ye1wake[k]*(y4wake[k]-ycwake[k])+ze1wake[k]
*(z4wakeqs[k]-zcwake[k]);
p4[1] =
xe2wake[k]*(x4wake[k]-xcwake[k])+ye2wake[k]*(y4wake[k]-ycwake[k])+ze2wake[k]
*(z4wakeqs[k]-zcwake[k]);
p4[2] =
xe3wake[k]*(x4wake[k]-xcwake[k])+ye3wake[k]*(y4wake[k]-ycwake[k])+ze3wake[k]
*(z4wakeqs[k]-zcwake[k]);

source(pcolloc[0],pcolloc[1],pcolloc[2],p1[0],p1[1],p1[2],
p2[0],p2[1],p2[2],p3[0],p3[1],p3[2],
p4[0],p4[1],p4[2],&srcphi, &dblphi);

*(E+count2)= dblphi;
count2++;
}

}
return;
}

void mexFunction (int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{

/* Input variables */

int totpanelsf, totpanelswake;
double eps;

double *xcf, *ycf, *zcf;
double *x1f, *y1f, *z1f;
double *x2f, *y2f, *z2f;
double *x3f, *y3f, *z3f;
double *x4f, *y4f, *z4f;
double *xe1, *ye1, *ze1;
double *xe2, *ye2, *ze2;
double *nxf, *nyf, *nzf;
double *z1fqs, *z2fqs, *z3fqs, *z4fqs;

double *xcwake, *ycwake, *zcwake;
double *x1wake, *y1wake, *z1wake;
double *x2wake, *y2wake, *z2wake;
double *x3wake, *y3wake, *z3wake;
double *x4wake, *y4wake, *z4wake;
double *xe1wake, *ye1wake, *ze1wake;
double *xe2wake, *ye2wake, *ze2wake;
double *xe3wake, *ye3wake, *ze3wake;
double *z1wakeqs, *z2wakeqs, *z3wakeqs, *z4wakeqs;

/* Output variables */

double *A, *S, *E;
/* Assign scalars to input */

totpanelsf = mxGetScalar(prh s[0]);
totpanelswake = mxGetScalar(prh s[1]);
eps = mxGetScalar(prh s[2]);

/* Assign pointers to input */

xcf = mxGetPr(prhs[3]);
.....
.....
z3wakeqs = mxGetPr(prhs[57]);
z4wakeqs = mxGetPr(prhs[58]);

/* Create Matrices for the outputs */

plhs[0] = mxCreateDoubleM atrix(totpanels f,totpanelsf,mx REAL);
plhs[1] = mxCreateDoubleM atrix(totpanels f,totpanelsf,mx REAL);
plhs[2] = mxCreateDoubleM atrix(totpanels f,totpanelswake ,mxREAL);
/* Assign pointers to output */

A = mxGetPr(plhs[0]);
S = mxGetPr(plhs[1]);
E = mxGetPr(plhs[2]);

/* Call the coefficient matrix C subroutine */

coefficientmatr ix(totpanelsf,t otpanelswake,ep s,
xcf, ycf, zcf,
x1f, y1f, z1f,
x2f, y2f, z2f,
x3f, y3f, z3f,
x4f, y4f, z4f,
xe1, ye1, ze1,
xe2, ye2, ze2,
nxf, nyf, nzf,
z1fqs, z2fqs, z3fqs, z4fqs,
xcwake, ycwake, zcwake,
x1wake, y1wake, z1wake,
x2wake, y2wake, z2wake,
x3wake, y3wake, z3wake,
x4wake, y4wake, z4wake,
xe1wake, ye1wake, ze1wake,
xe2wake, ye2wake, ze2wake,
xe3wake, ye3wake, ze3wake,
z1wakeqs, z2wakeqs, z3wakeqs, z4wakeqs,
A, S, E);
return;
}

"Peter Pichler" <pi*****@pobox. sk> wrote in message
news:40******** @mk-nntp-2.news.uk.tisca li.com...
"Martijn van den Branden" <m.************ *@student.tudel ft.nl> wrote in
message news:bv******** **@news.tudelft .nl...
Hi, <snip>
would someone care to take a glance at the code
and maybe identify some beginners mistake that causes the erroneous

results?
I can send the code
as an attachment.


Don't send in an attachment, trim it down to a reasonable size (no more

than a few KB, but take care not to cut out the bits that show the problem) and
post it here.

Peter

Nov 14 '05 #3
Peter Pichler wrote:
"Martijn van den Branden" <m.************ *@student.tudel ft.nl> wrote

<snip>
would someone care to take a glance at the code and maybe
identify some beginners mistake that causes the erroneous
results? I can send the code as an attachment.


Don't send in an attachment, trim it down to a reasonable size
(no more than a few KB, but take care not to cut out the bits
that show the problem) and post it here.


But make sure it is still a compilable complete program. Cut and
paste it, with neither tabs nor // comments, and keep line lengths
below 72.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 14 '05 #4
Martijn van den Branden wrote:
I've included the full code below, but at places i've deleted declarations
of variables
where they are obvious replaced by ...


This is hopeless. Don't post uncompilable code. Deleting the declarations
is close to antisocial. #including a non-standard header is silly; if we
can't see what's there, it doesn't exist.
--
Martin Ambuhl
Nov 14 '05 #5
I'm sorry, but i must say your reaction is close to antisocial. like i said
in my first message, i've close to no experience writing in c and i would
be very grateful if someone could point out some erroneous c syntax
from looking at the code, if there should be any, i didn't mean to offend
anyone.
I cut out some code because the first person to respond to my question
advised it.
AndI thought that if i'm lucky people that have experience writing mex files
might read my question and point me in some direction. I'm sure to them
mex.h is familiar, if still non-standard.

"Martin Ambuhl" <ma*****@earthl ink.net> wrote in message
news:TA******** *********@newsr ead3.news.atl.e arthlink.net...
Martijn van den Branden wrote:
I've included the full code below, but at places i've deleted declarations of variables
where they are obvious replaced by ...
This is hopeless. Don't post uncompilable code. Deleting the

declarations is close to antisocial. #including a non-standard header is silly; if we
can't see what's there, it doesn't exist.
--
Martin Ambuhl

Nov 14 '05 #6
ok, here it comes again :). thanks for your answer!

_______________ _______________ _______________ ____________
#include "mex.h"
#include <math.h>
#define PI 3.14159

void source (double x, double y, double z, double x1, double y1, double z1,
double x2, double y2, double z2, double x3, double y3, double
z3,
double x4, double y4, double z4, double *srcphi, double
*dblphi)
{

double eps = 1e-10;
double d12,d23,d34,d41 ;
double r1,r2,r3,r4;
double e1,e2,e3,e4;
double h1,h2,h3,h4;
double m12,m23,m34,m41 ;

x1=x1+1*eps;
x2=x2-1*eps;
x3=x3+2*eps;
x4=x4-2*eps;

z1=0;
z2=0;
z3=0;
z4=0;

d12 = sqrt(pow((x2-x1),2) + pow((y2-y1),2));
d23 = sqrt(pow((x3-x2),2) + pow((y3-y2),2));
d34 = sqrt(pow((x4-x3),2) + pow((y4-y3),2));
d41 = sqrt(pow((x1-x4),2) + pow((y1-y4),2));

r1 = sqrt(pow((x-x1),2) + pow((y-y1),2) + pow(z,2));
r2 = sqrt(pow((x-x2),2) + pow((y-y2),2) + pow(z,2));
r3 = sqrt(pow((x-x3),2) + pow((y-y3),2) + pow(z,2));
r4 = sqrt(pow((x-x4),2) + pow((y-y4),2) + pow(z,2));

e1 = pow((x-x1),2) + pow(z,2);
e2 = pow((x-x2),2) + pow(z,2);
e3 = pow((x-x3),2) + pow(z,2);
e4 = pow((x-x4),2) + pow(z,2);

h1 = (x-x1)*(y-y1);
h2 = (x-x2)*(y-y2);
h3 = (x-x3)*(y-y3);
h4 = (x-x4)*(y-y4);

m12 = (y2-y1)/(x2-x1);
m23 = (y3-y2)/(x3-x2);
m34 = (y4-y3)/(x4-x3);
m41 = (y1-y4)/(x1-x4);

*(srcphi) = -1.0/(4*PI)*(
(
(((x-x1)*(y2-y1)-(y-y1)*(x2-x1))/d12)*log((r1+r2 +d12)/(r1+r2-d12)) +
(((x-x2)*(y3-y2)-(y-y2)*(x3-x2))/d23)*log((r2+r3 +d23)/(r2+r3-d23)) +
(((x-x3)*(y4-y3)-(y-y3)*(x4-x3))/d34)*log((r3+r4 +d34)/(r3+r4-d34)) +
(((x-x4)*(y1-y4)-(y-y4)*(x1-x4))/d41)*log((r4+r1 +d41)/(r4+r1-d41))
)
+fabs(z)*(
atan((m12*e1-h1)/(z*r1)) - atan((m12*e2-h2)/(z*r2)) +
atan((m23*e2-h2)/(z*r2)) - atan((m23*e3-h3)/(z*r3)) +
atan((m34*e3-h3)/(z*r3)) - atan((m34*e4-h4)/(z*r4)) +
atan((m41*e4-h4)/(z*r4)) - atan((m41*e1-h1)/(z*r1))
)
);

*(dblphi) = -1.0/(4*PI)*(
atan((m12*e1-h1)/(z*r1)) - atan((m12*e2-h2)/(z*r2))
+ atan((m23*e2-h2)/(z*r2)) - atan((m23*e3-h3)/(z*r3))
+ atan((m34*e3-h3)/(z*r3)) - atan((m34*e4-h4)/(z*r4))
+ atan((m41*e4-h4)/(z*r4)) - atan((m41*e1-h1)/(z*r1)));

return;
}


void coefficientmatr ix(int totpanelsf, int totpanelswake, double eps,
double *xcf, double *ycf, double *zcf,
double *x1f, double *y1f, double *z1f,
double *x2f, double *y2f, double *z2f,
double *x3f, double *y3f, double *z3f,
double *x4f, double *y4f, double *z4f,
double *xe1, double *ye1, double *ze1,
double *xe2, double *ye2, double *ze2,
double *nxf, double *nyf, double *nzf,
double *z1fqs, double *z2fqs, double *z3fqs, double
*z4fqs,
double *xcwake, double *ycwake, double *zcwake,
double *x1wake, double *y1wake, double *z1wake,
double *x2wake, double *y2wake, double *z2wake,
double *x3wake, double *y3wake, double *z3wake,
double *x4wake, double *y4wake, double *z4wake,
double *xe1wake, double *ye1wake, double *ze1wake,
double *xe2wake, double *ye2wake, double *ze2wake,
double *xe3wake, double *ye3wake, double *ze3wake,
double *z1wakeqs, double *z2wakeqs, double *z3wakeqs,
double *z4wakeqs,
double *A, double *S, double *E)
{
int i,j,k,count = 0,count2=0;
double xp, yp, zp;
double pcolloc[3], p1[3], p2[3], p3[3], p4[3];
double srcphi, dblphi;

for(i=0;i<totpa nelsf;i++)
{

xp = xcf[i]-nxf[i]*eps;
yp = ycf[i]-nyf[i]*eps;
zp = zcf[i]-nzf[i]*eps;

for (j=0;j<totpanel sf;j++)
{

pcolloc[0] = xe1[j]*(xp-xcf[j])+ye1[j]*(yp-ycf[j])+ze1[j]*(zp-zcf[j]);
pcolloc[1] = xe2[j]*(xp-xcf[j])+ye2[j]*(yp-ycf[j])+ze2[j]*(zp-zcf[j]);
pcolloc[2] = nxf[j]*(xp-xcf[j])+nyf[j]*(yp-ycf[j])+nzf[j]*(zp-zcf[j]);

p1[0] =
xe1[j]*(x1f[j]-xcf[j])+ye1[j]*(y1f[j]-ycf[j])+ze1[j]*(z1fqs[j]-zcf[j]);
p1[1] =
xe2[j]*(x1f[j]-xcf[j])+ye2[j]*(y1f[j]-ycf[j])+ze2[j]*(z1fqs[j]-zcf[j]);
p1[2] =
nxf[j]*(x1f[j]-xcf[j])+nyf[j]*(y1f[j]-ycf[j])+nzf[j]*(z1fqs[j]-zcf[j]);

p2[0] =
xe1[j]*(x2f[j]-xcf[j])+ye1[j]*(y2f[j]-ycf[j])+ze1[j]*(z2fqs[j]-zcf[j]);
p2[1] =
xe2[j]*(x2f[j]-xcf[j])+ye2[j]*(y2f[j]-ycf[j])+ze2[j]*(z2fqs[j]-zcf[j]);
p2[2] =
nxf[j]*(x2f[j]-xcf[j])+nyf[j]*(y2f[j]-ycf[j])+nzf[j]*(z2fqs[j]-zcf[j]);

p3[0] =
xe1[j]*(x3f[j]-xcf[j])+ye1[j]*(y3f[j]-ycf[j])+ze1[j]*(z3fqs[j]-zcf[j]);
p3[1] =
xe2[j]*(x3f[j]-xcf[j])+ye2[j]*(y3f[j]-ycf[j])+ze2[j]*(z3fqs[j]-zcf[j]);
p3[2] =
nxf[j]*(x3f[j]-xcf[j])+nyf[j]*(y3f[j]-ycf[j])+nzf[j]*(z3fqs[j]-zcf[j]);

p4[0] =
xe1[j]*(x4f[j]-xcf[j])+ye1[j]*(y4f[j]-ycf[j])+ze1[j]*(z4fqs[j]-zcf[j]);
p4[1] =
xe2[j]*(x4f[j]-xcf[j])+ye2[j]*(y4f[j]-ycf[j])+ze2[j]*(z4fqs[j]-zcf[j]);
p4[2] =
nxf[j]*(x4f[j]-xcf[j])+nyf[j]*(y4f[j]-ycf[j])+nzf[j]*(z4fqs[j]-zcf[j]);

source(pcolloc[0],pcolloc[1],pcolloc[2],p1[0],p1[1],p1[2],
p2[0],p2[1],p2[2],p3[0],p3[1],p3[2],
p4[0],p4[1],p4[2],&srcphi, &dblphi);

*(S+count)= srcphi;
*(A+count)= dblphi;
count++;
}

for (k=0;k<totpanel swake;k++)
{

pcolloc[0] =
xe1wake[k]*(xp-xcwake[k])+ye1wake[k]*(yp-ycwake[k])+ze1wake[k]*(zp-zcwake[k]
);
pcolloc[1] =
xe2wake[k]*(xp-xcwake[k])+ye2wake[k]*(yp-ycwake[k])+ze2wake[k]*(zp-zcwake[k]
);
pcolloc[2] =
xe3wake[k]*(xp-xcwake[k])+ye3wake[k]*(yp-ycwake[k])+ze3wake[k]*(zp-zcwake[k]
);

p1[0] =
xe1wake[k]*(x1wake[k]-xcwake[k])+ye1wake[k]*(y1wake[k]-ycwake[k])+ze1wake[k]
*(z1wakeqs[k]-zcwake[k]);
p1[1] =
xe2wake[k]*(x1wake[k]-xcwake[k])+ye2wake[k]*(y1wake[k]-ycwake[k])+ze2wake[k]
*(z1wakeqs[k]-zcwake[k]);
p1[2] =
xe3wake[k]*(x1wake[k]-xcwake[k])+ye3wake[k]*(y1wake[k]-ycwake[k])+ze3wake[k]
*(z1wakeqs[k]-zcwake[k]);

p2[0] =
xe1wake[k]*(x2wake[k]-xcwake[k])+ye1wake[k]*(y2wake[k]-ycwake[k])+ze1wake[k]
*(z2wakeqs[k]-zcwake[k]);
p2[1] =
xe2wake[k]*(x2wake[k]-xcwake[k])+ye2wake[k]*(y2wake[k]-ycwake[k])+ze2wake[k]
*(z2wakeqs[k]-zcwake[k]);
p2[2] =
xe3wake[k]*(x2wake[k]-xcwake[k])+ye3wake[k]*(y2wake[k]-ycwake[k])+ze3wake[k]
*(z2wakeqs[k]-zcwake[k]);

p3[0] =
xe1wake[k]*(x3wake[k]-xcwake[k])+ye1wake[k]*(y3wake[k]-ycwake[k])+ze1wake[k]
*(z3wakeqs[k]-zcwake[k]);
p3[1] =
xe2wake[k]*(x3wake[k]-xcwake[k])+ye2wake[k]*(y3wake[k]-ycwake[k])+ze2wake[k]
*(z3wakeqs[k]-zcwake[k]);
p3[2] =
xe3wake[k]*(x3wake[k]-xcwake[k])+ye3wake[k]*(y3wake[k]-ycwake[k])+ze3wake[k]
*(z3wakeqs[k]-zcwake[k]);

p4[0] =
xe1wake[k]*(x4wake[k]-xcwake[k])+ye1wake[k]*(y4wake[k]-ycwake[k])+ze1wake[k]
*(z4wakeqs[k]-zcwake[k]);
p4[1] =
xe2wake[k]*(x4wake[k]-xcwake[k])+ye2wake[k]*(y4wake[k]-ycwake[k])+ze2wake[k]
*(z4wakeqs[k]-zcwake[k]);
p4[2] =
xe3wake[k]*(x4wake[k]-xcwake[k])+ye3wake[k]*(y4wake[k]-ycwake[k])+ze3wake[k]
*(z4wakeqs[k]-zcwake[k]);

source(pcolloc[0],pcolloc[1],pcolloc[2],p1[0],p1[1],p1[2],
p2[0],p2[1],p2[2],p3[0],p3[1],p3[2],
p4[0],p4[1],p4[2],&srcphi, &dblphi);

*(E+count2)= dblphi;
count2++;
}

}
return;
}

void mexFunction (int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{

/* Input variables */

int totpanelsf, totpanelswake;
double eps;

double *xcf, *ycf, *zcf;
double *x1f, *y1f, *z1f;
double *x2f, *y2f, *z2f;
double *x3f, *y3f, *z3f;
double *x4f, *y4f, *z4f;
double *xe1, *ye1, *ze1;
double *xe2, *ye2, *ze2;
double *nxf, *nyf, *nzf;
double *z1fqs, *z2fqs, *z3fqs, *z4fqs;

double *xcwake, *ycwake, *zcwake;
double *x1wake, *y1wake, *z1wake;
double *x2wake, *y2wake, *z2wake;
double *x3wake, *y3wake, *z3wake;
double *x4wake, *y4wake, *z4wake;
double *xe1wake, *ye1wake, *ze1wake;
double *xe2wake, *ye2wake, *ze2wake;
double *xe3wake, *ye3wake, *ze3wake;
double *z1wakeqs, *z2wakeqs, *z3wakeqs, *z4wakeqs;

/* Output variables */

double *A, *S, *E;
/* Assign scalars to input */

totpanelsf = mxGetScalar(prh s[0]);
totpanelswake = mxGetScalar(prh s[1]);
eps = mxGetScalar(prh s[2]);

/* Assign pointers to input */

xcf = mxGetPr(prhs[3]);
ycf = mxGetPr(prhs[4]);
zcf = mxGetPr(prhs[5]);

x1f = mxGetPr(prhs[6]);
y1f = mxGetPr(prhs[7]);
z1f = mxGetPr(prhs[8]);

x2f = mxGetPr(prhs[9]);
y2f = mxGetPr(prhs[10]);
z2f = mxGetPr(prhs[11]);

x3f = mxGetPr(prhs[12]);
y3f = mxGetPr(prhs[13]);
z3f = mxGetPr(prhs[14]);

x4f = mxGetPr(prhs[15]);
y4f = mxGetPr(prhs[16]);
z4f = mxGetPr(prhs[17]);

xe1 = mxGetPr(prhs[18]);
ye1 = mxGetPr(prhs[19]);
ze1 = mxGetPr(prhs[20]);

xe2 = mxGetPr(prhs[21]);
ye2 = mxGetPr(prhs[22]);
ze2 = mxGetPr(prhs[23]);

nxf = mxGetPr(prhs[24]);
nyf = mxGetPr(prhs[25]);
nzf = mxGetPr(prhs[26]);

z1fqs = mxGetPr(prhs[27]);
z2fqs = mxGetPr(prhs[28]);
z3fqs = mxGetPr(prhs[29]);
z4fqs = mxGetPr(prhs[30]);

xcwake = mxGetPr(prhs[31]);
ycwake = mxGetPr(prhs[32]);
zcwake = mxGetPr(prhs[33]);

x1wake = mxGetPr(prhs[34]);
y1wake = mxGetPr(prhs[35]);
z1wake = mxGetPr(prhs[36]);

x2wake = mxGetPr(prhs[37]);
y2wake = mxGetPr(prhs[38]);
z2wake = mxGetPr(prhs[39]);

x3wake = mxGetPr(prhs[40]);
y3wake = mxGetPr(prhs[41]);
z3wake = mxGetPr(prhs[42]);

x4wake = mxGetPr(prhs[43]);
y4wake = mxGetPr(prhs[44]);
z4wake = mxGetPr(prhs[45]);

xe1wake = mxGetPr(prhs[46]);
ye1wake = mxGetPr(prhs[47]);
ze1wake = mxGetPr(prhs[48]);

xe2wake = mxGetPr(prhs[49]);
ye2wake = mxGetPr(prhs[50]);
ze2wake = mxGetPr(prhs[51]);

xe3wake = mxGetPr(prhs[52]);
ye3wake = mxGetPr(prhs[53]);
ze3wake = mxGetPr(prhs[54]);

z1wakeqs = mxGetPr(prhs[55]);
z2wakeqs = mxGetPr(prhs[56]);
z3wakeqs = mxGetPr(prhs[57]);
z4wakeqs = mxGetPr(prhs[58]);

/* Create Matrices for the outputs */

plhs[0] = mxCreateDoubleM atrix(totpanels f,totpanelsf,mx REAL);
plhs[1] = mxCreateDoubleM atrix(totpanels f,totpanelsf,mx REAL);
plhs[2] = mxCreateDoubleM atrix(totpanels f,totpanelswake ,mxREAL);
/* Assign pointers to output */

A = mxGetPr(plhs[0]);
S = mxGetPr(plhs[1]);
E = mxGetPr(plhs[2]);

/* Call the coefficient matrix C subroutine */

coefficientmatr ix(totpanelsf,t otpanelswake,ep s,
xcf, ycf, zcf,
x1f, y1f, z1f,
x2f, y2f, z2f,
x3f, y3f, z3f,
x4f, y4f, z4f,
xe1, ye1, ze1,
xe2, ye2, ze2,
nxf, nyf, nzf,
z1fqs, z2fqs, z3fqs, z4fqs,
xcwake, ycwake, zcwake,
x1wake, y1wake, z1wake,
x2wake, y2wake, z2wake,
x3wake, y3wake, z3wake,
x4wake, y4wake, z4wake,
xe1wake, ye1wake, ze1wake,
xe2wake, ye2wake, ze2wake,
xe3wake, ye3wake, ze3wake,
z1wakeqs, z2wakeqs, z3wakeqs, z4wakeqs,
A, S, E);
return;
}

"CBFalconer " <cb********@yah oo.com> wrote in message
news:40******** *******@yahoo.c om...
Peter Pichler wrote:
"Martijn van den Branden" <m.************ *@student.tudel ft.nl> wrote

<snip>
would someone care to take a glance at the code and maybe
identify some beginners mistake that causes the erroneous
results? I can send the code as an attachment.


Don't send in an attachment, trim it down to a reasonable size
(no more than a few KB, but take care not to cut out the bits
that show the problem) and post it here.


But make sure it is still a compilable complete program. Cut and
paste it, with neither tabs nor // comments, and keep line lengths
below 72.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 14 '05 #7
Martijn van den Branden wrote:

But make sure it is still a compilable complete program. Cut and
paste it, with neither tabs nor // comments, and keep line lengths
below 72.


ok, here it comes again :). thanks for your answer!

.... great big snip ...

Note the words compilable complete above. Non-standard include
files must be present, together with their associated source.
Your exercise in cutting it down to that in the first place will
often reveal the problem.

Without these rules the result is usually pure gibberish.

Oh yes - please do not toppost. I fixed this one.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #8
Martijn van den Branden wrote:
I've included the full code below, but at places i've deleted declarations
of variables
where they are obvious replaced by ...

Thanks in advance,

Martijn


#include "mex.h"


gcc -g -W -Wall -ansi -pedantic -o foo foo.c -lm
foo.c:1: mex.h: No such file or directory

That's going to be a problem for anyone trying to help you.

<snip>

--
Richard Heathfield : bi****@eton.pow ernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #9
Sorry guys. I understand it's no use without mex.h, except for those maybe
who use matlab and write mex (matlab executables) themselves, and have
it installed with their matlab product. I'm sure the people at mathworks
would
not like it if i distributed mex.h myself :).

Thanks for your time!


"CBFalconer " <cb********@yah oo.com> wrote in message
news:40******** *******@yahoo.c om...
Martijn van den Branden wrote:

But make sure it is still a compilable complete program. Cut and
paste it, with neither tabs nor // comments, and keep line lengths
below 72.


ok, here it comes again :). thanks for your answer!

... great big snip ...

Note the words compilable complete above. Non-standard include
files must be present, together with their associated source.
Your exercise in cutting it down to that in the first place will
often reveal the problem.

Without these rules the result is usually pure gibberish.

Oh yes - please do not toppost. I fixed this one.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 14 '05 #10

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

Similar topics

2
1889
by: James | last post by:
Hi I am having some trouble getting a asp page to load. Im a noob to the asp side. I have followed knowledege base Article 301305. I am running 2000 adv, IIS 5.0 I have the following settings to the folder that has the asp. Application settings
4
3847
by: Jacek Dziedzic | last post by:
Hi! First of all, I hope my problem is not too loosely tied to the "standard C++" that is the topic of this group. I have some code that exhibits a strange behaviour: on one computer, where I compile with g++-3.2 it compiles and works fine, on another computer, whether I compile with g++-3.0 or g++-2.95 (unfortunately 3.2 is not available) it crashes with a segmentation violation on runtime.
0
1565
by: Paul C | last post by:
Hello, everybody. I am having trouble running some of the VS.NET samples, specifically the CarSelector web app, which is very simple. The symptom is that the web controls (drop down listboxes and such) do not render correctly. They're almost invisible, and the others don't work at all, but just show their caption text. Not what should happen This strange behavior is happening on my new laptop, which came with XP Home, but I immediately...
0
1509
by: Alexandre Jaquet | last post by:
Hi does anybody know how to solve my trouble, when I try to create a MS Office project I always got trouble. I can't create office project when I try to create one vs.net restart ... :s
2
5780
by: Jeff | last post by:
/* -------------------------------------------------------------------------- Hello, I was experimenting with class templates and specializing member functions and came across a simple problem which I can't figure out. I have a simple class C with 2 template member objects, and a function print() that prints the value of these objects. I defined a specialization of print() for C<string, char> which is called correctly. Then I wanted...
1
2006
by: Jim Bancroft | last post by:
Hi everyone, I'm running into a problem with my ASP.Net application. I've just created a new aspx page which uses some new components of mine that inherit from ServicedComponent and are designed to run under COM+. This page works fine, unless I get fancy and hit my browser's refresh button quickly, as a test. Then, what I see happen is the transactions pile up and my ASP.Net "current requests" do the same. This happens even with two...
6
3809
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for one day): \\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During Execution: 7 \\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
3
5006
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : >************************************************************************ > <WebMethod(), System.Web.Services.Protocols.SoapRpcMethod()> _ > Public Function HelloWorld() As > <System.Xml.Serialization.SoapElementAttribute("return")> String
2
1557
by: JLupear | last post by:
I am having trouble with my code again, I had prepared a question and the code to upload, however I am having trouble posting it, are there limits to the amount of lines you can post? I split it into 4 parts and am still having trouble uploading it. What am I doing wrong?
0
1679
by: mrchatgroup | last post by:
news from http://www.mrchat.net/myblog/myblog/small-accidents-mean-big-trouble-for-supercollider.html Small Accidents Mean Big Trouble for Supercollider Image Scientists expect startup glitches in the massive, complex machines they use to smash atoms.
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.