calculating the integral with dummy variables

25 views (last 30 days)
FANI on 1 Oct 2014
Commented: FANI on 2 Oct 2014
I have a problem in calculating the derivative that I uploaded. I have to use dummy variables for the integral but I can't do it.
Could you help me please?

Answers (1)

Mike Hosea
Mike Hosea on 1 Oct 2014
A "dummy" variable is a variable that is integrated out of the equation. All definite integrals use "dummy" variables in their formulation, so I don't understand the question. The only thing I can think that you might mean is that you need to express the integrals in a parameterized way, i.e. in a form where the result is not a constant, rather a function of the parameters that need to be specified. That is done using anonymous functions. For example, suppose
f = @(x,c)x.^2 + c
and I need to integrate f from 0 to 1. I can do this by creating an anonymous function that binds the value of c when it is needed.
Now if you try to run that as-is, without first defining c, you will get the error
Undefined function or variable 'c'.
Or if c was already defined, it will use that value of c and no other. What we need to do is make this a function, and thereby defer its evaluation until we give it the c we want it to use.
qs = @(c)integral(@(x)f(x,c),0,1)
Now we can evaluate qs with different values of c:
>> qs(1)
ans =
>> qs(2)
ans =
>> qs(3)
ans =
But we can't do this yet
>> qs(1:3)
Error using +
Matrix dimensions must agree.
Error in @(x,c)x.^2+c
To make our function of c more useful in MATLAB, we need to enable it to process arrays and operate element-wise. This is done with ARRAYFUN:
>> q = @(c)arrayfun(qs,c)
q =
>> q(1:3)
ans =
1.333333333333333 2.333333333333334 3.333333333333334
So, by using function handles and deferring evaluation until the parameter values are available, we can represent the solution to a parameterized problem.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!