I want to obtain value of "W" for different combination of values of (psi,r) example. "W" for (psi=0.0001,r = 2.1891) ; (psi=0.001,r = 2.1940); (psi=0.01,r = 2.2373) and so on

조회 수: 2 (최근 30일)
psi = 0.001;
alpha = (12*psi)^(1/3);
r = 2.1940;
l1 = (r + alpha)*(r + alpha);
l1a = r*r - r*alpha + alpha*alpha;
L1 = log(l1/l1a);
t1 = (2*r - alpha) / (alpha*sqrt(3));
T1 = atan(t1);
l2 = (1 + alpha)*(1 + alpha);
l2a = (1*1) - (1*alpha) + (alpha*alpha);
L2 = log(l2/l2a);
t2 = (2*1 - alpha) / (alpha*sqrt(3));
T2 = atan(t2);
W1 = 4 * sqrt(3) * (T1 - T2) * log((r+alpha)/(1+alpha));
W2 = (L1 - L2)*log((r*r - r*alpha + alpha*alpha)/(1 - alpha + alpha*alpha));
W3 = 4*(T1 -T2)*(T1 -T2);
W4 = (L1 - L2) + 2 * sqrt(3) * (T1 - T2);
W5 = 3 ./ ((r - 1) * (r - 1));
W = ((W1 + W2 -W3) * W5)/W4
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2022년 6월 22일
편집: Dyuman Joshi 2022년 6월 22일
Make it a function and call from workspace.
%calling individually
W1=calculateW(0.0001,2.1891)
W1 = 0.1602
W2=calculateW(0.001,2.194)
W2 = 0.1595
W3=calculateW(0.01,2.2373)
W3 = 0.1534
function W = calculateW(psi,r)
alpha = (12*psi)^(1/3);
l1 = (r + alpha)*(r + alpha);
l1a = r*r - r*alpha + alpha*alpha;
L1 = log(l1/l1a);
t1 = (2*r - alpha) / (alpha*sqrt(3));
T1 = atan(t1);
l2 = (1 + alpha)*(1 + alpha);
l2a = (1*1) - (1*alpha) + (alpha*alpha);
L2 = log(l2/l2a);
t2 = (2*1 - alpha) / (alpha*sqrt(3));
T2 = atan(t2);
W1 = 4 * sqrt(3) * (T1 - T2) * log((r+alpha)/(1+alpha));
W2 = (L1 - L2)*log((r*r - r*alpha + alpha*alpha)/(1 - alpha + alpha*alpha));
W3 = 4*(T1 -T2)*(T1 -T2);
W4 = (L1 - L2) + 2 * sqrt(3) * (T1 - T2);
W5 = 3 ./ ((r - 1) * (r - 1));
W = ((W1 + W2 -W3) * W5)/W4;
end
AVINASH SAHU
AVINASH SAHU 2022년 6월 22일
thank you for clarification but how can we use loop so that we don't have to enter manually for large dataset?

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

채택된 답변

Dyuman Joshi
Dyuman Joshi 2022년 6월 22일
%loop
psi=[0.0001,0.001,0.01];
r=[2.1891,2.194,2.2373];
for i=1:numel(psi)
W(i)=calculateW(psi(i),r(i));
end
W
W = 1×3
0.1602 0.1595 0.1534
%arrayfun
W1=arrayfun(@calculateW, psi, r)
W1 = 1×3
0.1602 0.1595 0.1534
function W = calculateW(psi,r)
alpha = (12*psi)^(1/3);
l1 = (r + alpha)*(r + alpha);
l1a = r*r - r*alpha + alpha*alpha;
L1 = log(l1/l1a);
t1 = (2*r - alpha) / (alpha*sqrt(3));
T1 = atan(t1);
l2 = (1 + alpha)*(1 + alpha);
l2a = (1*1) - (1*alpha) + (alpha*alpha);
L2 = log(l2/l2a);
t2 = (2*1 - alpha) / (alpha*sqrt(3));
T2 = atan(t2);
W1 = 4 * sqrt(3) * (T1 - T2) * log((r+alpha)/(1+alpha));
W2 = (L1 - L2)*log((r*r - r*alpha + alpha*alpha)/(1 - alpha + alpha*alpha));
W3 = 4*(T1 -T2)*(T1 -T2);
W4 = (L1 - L2) + 2 * sqrt(3) * (T1 - T2);
W5 = 3 ./ ((r - 1) * (r - 1));
W = ((W1 + W2 -W3) * W5)/W4;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by