🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Numerical Integral

User: "Altair Forum User"
Altair Employee
Updated by Altair Forum User

Hello,

 

I want to calculate numerical integration in Compose. I am using Compose 2017.3. In another script in Matlab 2016a, I was using integral2 function. I searched, but couldn't find this function in Compose. Is there another function available in Compose to calculate numerical integration?

 

Thank you

Berker

Find more posts tagged with

Sort by:
1 - 3 of 31
    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    Hello,

     

    I thought I need to provide more details regarding my question. Below please find a sample code I was running in Matlab 2016a. Here, I am using 'integral2' to calculate the double integral. This function was not available in Compose 2017.3. I try to use 'quad,' but I am not sure whether that function calculated double layer integral. Is there another function that I can use to calculate double layer integral?

     

    clear all;
    close all;
    clc;

    rr1=0.0305;
    rr2=0.0415;
    xmin=0;
    xmax=0.005416836077132;
    f = @(x,y) x.^2 + y.^2;
    ymin = @(x) sqrt(rr1^2 - x.^2);
    ymax = @(x) sqrt(rr2^2 - x.^2);
    moment = 2*integral2(f, xmin, xmax, ymin, ymax);
    matlab_result=1.5624e-7;
    disp(moment);

     

    Thank you

    Berker

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    Hello Berker,

          The best way to implement this in Compose is to nest trapz and quad functions. The following code may help you to solve your issue. 

     

    global rr1;
    global rr2;
    rr1 = 0.0305;
    rr2 = 0.0415;

    function q = f(x)
        global rr1;
        global rr2;
        g = @(y) (x*x + y.*y);
        v = [sqrt(rr1^2-x^2):0.000001:sqrt(rr2^2-x^2)];
        q = trapz(v, g(v));
    end

    xmin = 0;
    xmax = 0.005416836077132;
    moment = 2*quad(@f, xmin, xmax, [1.0e-10, 1.0e-10])
     

     

    Thanks,

    Sijo George

    User: "manoj kandukuri"
    Altair Employee
    Updated by manoj kandukuri

    modifying code suggested by @sijo george to run in newer versions of compose 2019.3 or above...

     

    function q = f(x)
        global rr1;
        global rr2;
        n=length(x);
        q=zeros(size(x));
        for j=1:n
            a = sqrt(rr1^2 - x(j)^2);
            b = sqrt(rr2^2-x(j)^2);
            g = @(y)(x(j)^2 + y.^2);
            q(j)=quad(g,a,b);
    end
    end

    xmin = 0;
    xmax = 0.005416836077132;
    moment = 2*quad(@f, xmin,xmax, [1.0e-10, 1.0e-10])

     

    Thanks,

    Manoj kandukuri