Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7937961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:40:07+00:00 2026-06-03T22:40:07+00:00

I wrote a code in matlab to compute an integral using Gauss-Chebyshev quadrature ,

  • 0

I wrote a code in matlab to compute an integral using Gauss-Chebyshev quadrature , but it doesn’t work:

function int = chebquad('-1i*exp(x+3)',1e-8,-1,1); 
f=inline('-1i*exp(x+3)','x')  
old_int = inf; 
for n=1:1000    
    x = cos(((2*(1:n) - 1)/(2*n))*pi);    
    w = pi/n;    
    fx = f(x);    
    int = sum(w.*fx);    
    if abs(int_old-int) < tol 
        break    
    end    
    old_int = int;   
end

Any suggestions?

Thanks!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:40:09+00:00Added an answer on June 3, 2026 at 10:40 pm

    for future reference, it would help us out that you didn’t display your function with the specified variable as constants:

    so show:

    function hv= someName(firstVar, secondVar)
    

    and not:

    function hv= someName(1, 'some string')
    

    I don’t know why you have both -1 and 1, but I’m assuming tol = 1e-8. That being said, you made a small mistake in your code by using int_old instead of old_int.

    Edit: so at first I thought, you just displayed the function for “our benefit”, now I think you didn’t even define a Matlab function properly. Please read this and learn about basic Matlab coding. Chebyshev–Gauss quadrature is defined over -1 to 1, and thus doesn’t need to be in a function code, below is the revised code:

    function intV = chebquad(funC,tol)
    
    f=inline(funC,'x');
    old_int = inf; 
    for n=1:1000    
        x = cos(((2*(1:n) - 1)/(2*n))*pi);    
        w = pi/n;    
        fx = f(x);    
        intV = sum(w.*fx);    
        if abs(old_int - intV) < tol 
            break    
        end    
        old_int = intV ;   
    end
    

    at the command prompt, you call this with:

    intV = chebquad('-1i*exp(x+3)', 1e-8)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote my code using this article at msdn as a primary helper My
i wrote following code to create a linkbutton programmatically, but its showing like lable
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I wrote this code. The constructor works normally, but in the destructor I get
LANGUAGE: I am writing an object-oriented code in MATLAB. I wrote almost all of
I'm trying to write some code to calculate a cumulative distribution function in matlab.
Basically, I have 10 data files and I wrote a MATLAB function to process
suppose that there is given following matlab code function dp = derp(p) n =
I'm going to attempt to optimize some code written in MATLAB, by using CUDA.
I'm trying to write a short Matlab code to perform a certain mathematical function.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.