How can I do sigma over functions

Hi all,
Suppose if I know y(j) and z(j) (suppose j varies from 1 to 100) and there are two functions : which vary with x,y,z and with the value of j
f1(x,y,z,y1(j),z1(j)),f2(x,y,z,y1(j),z1(j)).
And if f3(x,y,z,y1(j),z1(j))=f1*f2.
How can I do do summation of f3 over j?
I should be left with a function of x,y,z after summation over j. Can some one please tell me in a sequential way?
Thank you,
Srinath

回答 (1 件)

Matt J
Matt J 2013 年 7 月 2 日
編集済み: Matt J 2013 年 7 月 2 日

0 投票

If your functions are vectorized and written to return column vectors, then it should be straightforward. For example,
yj=rand(100,1); %fake y(j)
zj=rand(100,1); %fake z(j)
f1=@(x,y,z) x+y+z+yj+zj;
f2=@(x,y,z) 2*(x+y+z).^2+yj.^2+zj.^2;
then
f3=@(x,y,z) sum(f1(x,y,z).*f2(x,y,z));
and you can then do things like,
>> f3(1,2,1)
ans =
1.6280e+04

4 件のコメント

srinath
srinath 2013 年 7 月 3 日
編集済み: srinath 2013 年 7 月 3 日
Thanks for your reply. It worked for most of my work. But there is some problem. Actually, I have three such f3's and I will have to solve for x,y,z using the three expressions(like f3).
I know that there is 'solve' command. But it is not working here. I used it like this. Please correct me if you can
sum1,sum2,sum3 are three summations.
[x,y,z]=solve(sum1,sum2,sum3,x,y,z);
I am getting an error like this
Error using internal.matlab.Message In 'symbolic:solve:errmsg1', data type supplied is incorrect for parameter {1}.
Error in message (line 11) msgObj = internal.matlab.Message(msgID,varargin{:});
Error in solve>processString (line 337) error(message('symbolic:solve:errmsg1', v))
Error in solve>getEqns (line 267) eqns = processString(eqns, v, vc);
Error in solve (line 150) [eqns,vars,options] = getEqns(varargin{:});
Error in expression (line 34) [y1 z1 theta]=solve(sum1,sum2,sum3);
Matt J
Matt J 2013 年 7 月 3 日
You should probably be using FSOLVE instead
F=@(p) [sum1(p(1),p(2),p(3));...
sum2(p(1),p(2),p(3));...
sum3(p(1),p(2),p(3))];
fsolve(F,initialpoint);
srinath
srinath 2013 年 7 月 5 日
I didn't get what are those p(1),p(2),p(3). Also,what should I keep for the initial point. Because the solution that I finally get will depend on initial point right? Can you just elaborate that? Thanks again.
Matt J
Matt J 2013 年 7 月 5 日
編集済み: Matt J 2013 年 7 月 5 日
p is a vector whose components p(1),p(2), and p(3) are your 3 unknowns. As you've been saying throughout, the quantities sum1, sum2, and sum3 depend on 3 unknown variables, so sum1(p(1), p(2), p(3)) is a way to express that in terms of a single unknown vector, p.
Yes, the solution could depend on the initial point if you have multiple solutions. In that case, you have to choose the initial guess based on approximate knowledge of where the particular solution you're looking for might lie. But that's always the burden in equation solving, when a symbolic solution of the equations is unavailable.

サインインしてコメントする。

カテゴリ

質問済み:

2013 年 7 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by