Resolve Integration in Matlab with B(m,n) Function | Troubleshooting Tips

In summary, the conversation discussed a problem with a function that was not properly defined and used in a code. The expert advised to hardcode the function and use the 'quad' function correctly in order to evaluate the integral. An example of a more complex function was provided to show how to properly substitute values for m and n.
  • #1
ruby_duby
46
0
I have a function

B(m,n) = Integration of this between 1 and 0 (x.^m-1).*((1-x).^n-1)

For my m file i have

function Beta = B(m,n)
x=quad('@B',0,1);
Beta=(x.^m-1).*((1-x).^n-1);

however when i run my m-file it doesn't work. Can anybody help me please
 
Physics news on Phys.org
  • #2
ruby_duby said:
I have a function

B(m,n) = Integration of this between 1 and 0 (x.^m-1).*((1-x).^n-1)

For my m file i have

function Beta = B(m,n)
x=quad('@B',0,1);
Beta=(x.^m-1).*((1-x).^n-1);

however when i run my m-file it doesn't work. Can anybody help me please

Two problems:
1) Your function is defined AFTER you call the quad function
2) Your function is improperly defined and used. Your function should be in terms of x (that's what you're varying), and not m and n (also, these had better be defined elsewhere, say m=1, n=2--quad will not give you a symbolic answer).

Go to the Mathworks documentation page for the quad function and carefully look at their example:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/quad.html
 
  • #3
thanks so much for your help but I still can't get it to work! I really find Matlab difficult and have virtually got every single book the library has to help me!

Ive tried fiddling around with my m-file but to no luck!

When i want to find B(2,3) and B(3,4) using ny m-file, i just get an error message.

I think its because i have no idea what I am doing so any guidance is really appreciated
 
  • #4
You didn't pay attention to what I said in my last post that you're not only using function handles incorrectly, but also the 'quad' function. To reiterate, hardcode your function (e.g. use x^2 or something, not x^m)! Without getting overly sophisticated, your function should not be in terms of m or n, but in terms of x. That's the only way you can use it in conjunction with the quad function. Quad is substituting in values only for x, not for m and n! Also, you cannot just declare a function mid-way through an m-file.

I'll take at face value that this isn't a homework problem. The following is how you can get what I think you're trying to achieve by having MATLAB do the substitution for you. Try declaring a more complex function along the lines of the following:

Code:
function integral=quadEvaluator(m,n)
% Evaluates the integral of (x.^m-1).*((1-x).^n-1)
% over the interval 0<x<1 and with given input values of m and n

functionString = ['(x.^', num2str(m), '-1).*((1-x).^', num2str(n), '-1)'];
% Creates the equation substituting in values of m and n
% Using the square braces concatenates everything together

fprintf('Evaluating the integral of ')
fprintf(functionString)
fprintf(' over the interval 0<x<1)
% Nice printout to verify the proper function is being evaluated

integral = quad(functionString, 0, 1);

When you try to evaluate something, it should give you an answer

>> junkVariable = quadEvaluator(2,3)

Evaluating the integral of (x.^2-1).*((1-x).^3-1) over the interval 0<x<1
junkVariable = 0.4333

In the future, it would also help if you posted what the error message was, instead of just saying that you have an error message.
 

1. What is Resolve Integration in Matlab?

Resolve Integration in Matlab is a method used to numerically solve integrals, which are mathematical expressions that involve the area under a curve. It utilizes the B(m,n) function, which is a special type of beta function, to calculate the integral values.

2. How do I use the B(m,n) function in Resolve Integration?

To use the B(m,n) function in Resolve Integration, you need to first define the function in your code using the "beta" function in Matlab. Then, you can use the "integral" function with the defined B(m,n) function to solve the integral for a given range of values.

3. Why is my Resolve Integration code not working?

There could be several reasons why your Resolve Integration code is not working. Some common troubleshooting tips to consider are:

  • Check if you have properly defined the B(m,n) function in your code.
  • Make sure your integral limits are appropriate for the function being integrated.
  • Check for any syntax errors in your code.
  • If using data points, ensure that they are correctly formatted and in the correct order.
  • Try using a different method of integration, such as the "quad" function in Matlab.

4. Can I use Resolve Integration for multiple integrals?

Yes, you can use Resolve Integration for multiple integrals by nesting the "integral" function within another "integral" function. This allows you to solve integrals with multiple variables.

5. Is Resolve Integration accurate?

Resolve Integration is a numerical method for solving integrals, so the accuracy of the results will depend on the number of iterations used and the chosen integration method. It is generally accurate for simple integrals, but for more complex ones, it may be necessary to increase the number of iterations or use a different method for better accuracy.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
992
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Calculus and Beyond Homework Help
Replies
3
Views
260
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
560
Back
Top