calculating the integral with dummy variables

조회 수: 6 (최근 30일)
FANI
FANI 2014년 10월 1일
댓글: FANI 2014년 10월 2일
Hi,
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?

답변 (1개)

Mike Hosea
Mike Hosea 2014년 10월 1일
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.
integral(@(x)f(x,c),0,1)
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 =
1.333333333333333
>> qs(2)
ans =
2.333333333333334
>> qs(3)
ans =
3.333333333333334
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 =
@(c)arrayfun(qs,c)
>> 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.

카테고리

Help CenterFile Exchange에서 Function Creation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by