how to implement following function in matlab?

 채택된 답변

Walter Roberson
Walter Roberson 2019년 3월 31일

0 개 추천

M = @(i) abs(v(i)) .* sum( abs(v(1:n)) .* abs(y(i,1:n)) .* cos(q(i,1:n) + d(1:n) - d(i)) );
If n is the same as length(v) and size(y,2) and length(d) then the code can be written more compactly.

댓글 수: 10

I need solution of below equation and please give the matlab code for it.
n=size of matrix y
Change v(1:n) to reshape(v(1:n),1,[])
This is what i am getting solution on commad window.
I request you to give the full code based on above function.
M =
@(i)abs(v(i)).*sum(abs(reshape(v(1:n),1,[])).*abs(y(i,1:n)).*cos(angle(y(i,1:n)+angle(y(1:n)-angle(y(i))))))
the following is the code i have tried in matlab.
j=sqrt(2);
y=[1+j*1 1+j*2
2+j*3 3+j*3];
V=[1+j*0
1+j*3];
i=1;
n=2;
M = @(i) abs(v(i)) .* sum( abs(reshape(v(1:n),1,[])) .* abs(y(i,1:n)) .* cos(angle(y(i,1:n) + angle(y(1:n) - angle(y(i))))))
please give me the exact code.
j=sqrt(2);
y=[1+j*1 1+j*2
2+j*3 3+j*3];
v=[1+j*0
1+j*3];
i=1;
n=2;
M = @(i) abs(v(i)) .* sum( abs(reshape(v(1:n),1,[])) .* abs(y(i,1:n)) .* cos(angle(y(i,1:n) + angle(y(1:n) - angle(y(i))))))
The only difference is that your formula was defined in terms of lower-case v, but you created a variable with upper-case V.
Note that what you posted gives a formula: it means "given a particular value for i, here is the calculation you need to make". The M that you get from my code is a formula : you have to invoke it with a particular value of i in order to get the answer. For example,
M(2)
The value that you pass in must not exceed the number of rows in y.
j=sqrt(2);
y=[5.882-j*23.528 -2.941+j*11.764 -2.941+j*11.764
-2.941+j*11.764 5.882-j*23.528 -2.941+j*11.764
-2.941+j*11.764 -2.941+j*11.764 5.882-j*23.528];
v=[1.04+j*0
1+j*0
1.04+j*0];
i=2;
n=3;
M = @(i) abs(v(i)) .* sum( abs(reshape(v(1:n),1,[])) .* abs(y(i,1:n)) .* cos(angle(y(i,1:n) + angle((reshape(v(1:n),1,[]))-angle(v(i))))));
M(2)
M2=(abs(v2)*abs(v1)*abs(ybus(2,1))*cos((angle(ybus(2,1)))+del1-del2))+(abs(v2)*abs(v2)*abs(ybus(2,2))*cos(angle(ybus(2,2))))+(abs(v2)*abs(v3)*abs(ybus(2,3))*cos((angle(ybus(2,3))+del3-del2)))
the above is the code
after expanding the formula of M2 i have written the expansion,but i have not got M2 and M(2) as same;
got the answer thank you so much for your great reply.
i request you to give the standard code of above for any no of variables.
give the code for below function when k (is not equal to) i Screenshot (19).png
noti = @(i) setdiff(1:n,i);
M = @(i) abs(v(i)) .* sum( abs(reshape(v(noti(i)),1,[])) .* abs(y(i,noti(i))) .* cos(angle(y(i,noti(i)) + angle(y(noti(i)) - angle(y(i))))))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by