public inbox for gsl-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Jean-Max Redonnet <redonnet@lgmt-fab1.ups-tlse.fr>
To: Brian Gough <bjg@network-theory.co.uk>
Cc: gsl-discuss@sourceware.cygnus.com
Subject: Re: Some (probably) ridiculous questions
Date: Wed, 19 Dec 2001 13:20:00 -0000	[thread overview]
Message-ID: <01070712471300.13471@lgmt-fab5.ups-tlse.fr> (raw)
In-Reply-To: <15173.56028.740003.364874@debian>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2690 bytes --]

Le Vendredi  6 Juillet 2001 17:35, Brian Gough a écrit :

<snip>

>
> Hello,
>
> The gsl_function type is mainly designed for interfacing to the
> univariate gsl routines.  It is not really a general facility so it
> does not handle other cases that are not used in the library, such as
> surfaces.
>
> The way to handle this sort of situation is,
>
> -- define your own surface function type in the way that you normally
> would in your C-programs
>
> -- if you need to use a gsl routine, for example to integrate along a
> line, define a function to create the appropriate gsl_function by
> mapping from your surface type.
>
> Philosophically, calls to GSL routines, and the GSL types, can be at a
> "lower-level" than your program.
>
> regards
> Brian Gough

Thanks for your help to a definitively poor programmer (and mathematician)

But I'm not sure I really understand what you mean...

I think I have defined a surface function type as you proposed.
This part seems to work as expected.
but I don't see how to define a function to create the appropriate 
gsl_function...

Here the code :

#include <stdlib.h>
#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_diff.h>

#define RAD2DEG(X) (X*180/M_PI)
#define DEG2RAD(X) (X*M_PI/180)

struct surf_function_struct {
  double (* fx)(double u, double v);
  double (* fy)(double u, double v);
  double (* fz)(double u, double v);;
};

typedef struct surf_function_struct surf_function ;

double C0_fx(double u)
{
  return 80*u;
}

double C0_fy(double u)
{
  return 80*tan(DEG2RAD(22.5))*(u-0.5);
}

double C0_fz(double u)
{
  return 40;
}

double C1_fx(double u)
{
  return 80*u;
}

double C1_fy(double u)
{
  return -80*tan(DEG2RAD(22.5))*(u-0.5);
}

double C1_fz(double u)
{
  return -40;
}

double S_fx(double u, double v)
{
  return (1-v)*C0_fx(u)+v*C1_fx(u);
}

double S_fy(double u, double v)
{
  return (1-v)*C0_fy(u)+v*C1_fy(u);
}

double S_fz(double u, double v)
{
  return (1-v)*C0_fz(u)+v*C1_fz(u);
}

int main (void)
{
  double u,v;
  surf_function surf;

  u = 0.5;
  v = 0.5;
  surf.fx = &S_fx;
  surf.fy = &S_fy;
  surf.fz = &S_fz;
  
  printf("              | %f \n", S_fx(u,v));
  printf(" S(%.1f,%.1f) = | %f \n", u, v, S_fy(u,v));
  printf("              | %f \n", S_fz(u,v));

  printf("              | %f \n", surf.fx(u,v));
  printf(" S(%.1f,%.1f) = | %f \n", u, v, surf.fy(u,v));
  printf("              | %f \n", surf.fz(u,v));
  
  return 0;
}

You would be my definitive heroe if you can help me on this point.

Thanks.
-- 
===============================================================================
Veuillez noter ma nouvelle adresse électronique :
	mailto:redonnetNO@SPAMlgmt.ups-tlse.fr

  reply	other threads:[~2001-12-19 13:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-19 13:20 Jean-Max Redonnet
2001-12-19 13:20 ` Brian Gough
2001-12-19 13:20   ` Jean-Max Redonnet [this message]
2001-12-19 13:20     ` Brian Gough

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=01070712471300.13471@lgmt-fab5.ups-tlse.fr \
    --to=redonnet@lgmt-fab1.ups-tlse.fr \
    --cc=bjg@network-theory.co.uk \
    --cc=gsl-discuss@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).