Matlab density function evaluation using symprod
1 回表示 (過去 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 件のコメント
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
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) )
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!