Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Numerical Integration - Syntax/Style Query

  1. Dec 4, 2009 #1
    Hi,

    Pretext: I have no formal background in matlab or maths in general, so apologies if any of the following doesn't make sense. I am also new to this forum, so apologies if this post is incorrect in any way. [n.b. I also posted this thread on mathhelpforum.com]

    Context: Ok, so I wanted to find the response value for various parameter values, using the following equation:

    http://www.nitric.net/~pete/pictures/pj.integral.GIF [Broken]

    [If you can't see the image, it is an integration with infinite bounds over an equation consisting of a Gaussian probability density function multiplied by the the square of a Gaussian cumulative density function plus one minus the square of another Gaussian cumulative density function]

    I wasn't sure whether it was possible to do this using the matlab symbolic toolkit (syms), so I thought I'd take a crack at it using numerical integration, using the quad command. After much effort and confusion, I ended up with the following code.

    Code (Text):
    mu=0;
    sigma=1;
    s=0;
    alpha=0.4;
     
    mu=sprintf('%f', mu);
    sigma=sprintf('%f', sigma);
    s=sprintf('%f', s);
    alpha=sprintf('%f', alpha);
     
     
    f=strcat('normpdf(x+',s,',',mu,',sqrt(2)*',sigma,').*(normcdf(x,',mu,',sqrt(2)*',alpha,'*',sigma,').^2 + (1 - normcdf(x,',mu,',sqrt(2)*',alpha,'*',sigma,')).^2)');

    quad(f,-1000,1000)
     
    This code *DOES* appear to work (i.e. yields the expected answers). But it strikes me as being more than a little crude. My questions therefore are as follows:

    1. From a mathematical point of view, was using numerical integration with suitably wide bounds the right way to go about this problem?
    2. From a programming point of view, is there a more elegant way to execute the above numerical integration? (i.e. a better approach than wrapping everything up as one big string which is then passed to the quad function)

    Many thanks for your time,
    Best,
    pete
     
    Last edited by a moderator: May 4, 2017
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted



Similar Discussions: Matlab Numerical Integration - Syntax/Style Query
Loading...