There is a error in my code. I have attached the equaion and my code. Kindly correct the part where i went wrong.
3 次查看(过去 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 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!