Matlab density function evaluation using symprod

2 次查看(过去 30 天)
For a homework question we are required to write a matlab function to evaluate the above density function, Im having trouble thinking how to evaluate a function like this with series sums and products in it, below is my attempt about going about solving it, however it appears you can not lookup vector values in symprod?, would it be easier to use a for loop approach? I would appreciate some help on getting started on this one as Im very stuck.
%{
(a) Write a Matlab function
c = Clayton c(u, theta)
which returns the value of c(u)
with parameter θ=theta.
%}
function c = Clayton_c(u,theta)
d=length(u);
%Power of second braceted expression(Nb: No pwr1)
pwr2=(-1-theta);
%Power of the third bracketedexpression(Nb: No pwr1)
pwr3=(-d-(1/theta));
syms k
part1=symprod(1+theta*(k-1),k,1,d);
part2=(symprod(u(k),k,1,d).^pwr2);
part3=(1-d+(symsum((u(k)).^(-theta)),k,1,d).^pwr3);
c=part1.*part2.*part3;
end
  3 个评论
Tom Craven
Tom Craven 2016-11-19
Hi David, a straight numerical evaluation is fine, would you possibly be able to elaborate on how to do the first part ? at all evaluating from 0:d-1?.
David Goodmanson
David Goodmanson 2016-11-21
Hi Tom, I wish I had looked at this thread earlier. Maybe there is a way to be notified when someone adds a comment but if so I don't know what it is. Anyway, here is the idea.
j = 1:d; % vector of values of j
A = 1 + theta*(j-1); % vector of terms you need
first_part = prod(A); % product of all those
This is probably clearer than the original suggestion which would have gone j = 0:d-1; A = 1 + theta*j;

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2016-11-18
You are correct, you cannot look up vector values using the symbolic index using symsum or symprod . Instead you need to generate the entire vector and sum() or prod() it. So instead of
symsum( u(j).^(-theta), j, 1, d)
you would
sum( u(1:d) .^ (-theta) )
and since d is length of u, that could be simplified to
sum( u .^ (-theta) )

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by