There is a error in my code. I have attached the equaion and my code. Kindly correct the part where i went wrong.
조회 수: 2 (최근 30일)
이전 댓글 표시
CODE:
r1=sqrt((x+a1).^2+(y+a2).^2+(z.^2)) %a1,a2,x,y and z are defined
r2=sqrt((a1-x).^2+(y+a2).^2+(z.^2))
r3=sqrt((a1-x).^2+(y-a2).^2+(z.^2))
r4=sqrt((x+a1).^2+(y-a2).^2+(z.^2))
C4=-a1-x
C1=-C4
C3=-a1+x
C2=-C3
d1=y+a2
d2=d1
d3=y-a2
d4=d3
I=2
for i=1:1:4
B=(((-1)^i*d(i))/(r(i)*(r(i)+((-1)^(i+1)*C(i)))))-(C(i)/(r(i)*(r(i)+d(i))))
Bz=((u*I)/(4*pi))*B
end
plot(z,Bz)
ERROR:
Undefined function or variable 'C'.
댓글 수: 0
답변 (1개)
Mark Sherstan
2019년 1월 29일
You never defined a "C" variable. You have C1, C2, etc... but not just "C". Additionally, you need to perform a summation in the loop (you are currently just redefining B each time) so you should adjust the end of your code as such:
...
B = 0;
for i=1:1:4
B = (((-1)^i*d(i))/(r(i)*(r(i)+((-1)^(i+1)*C(i)))))-(C(i)/(r(i)*(r(i)+d(i))))
B = B + B;
end
Bz=((u*I)/(4*pi))*B
plot(z,Bz)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!