Matlab code for Engineering Physics not working
이전 댓글 표시

CODE
%Assigning values of required constants
k=1/(4*pi*8.542e-12) ;
z=linspace(-0.5,0.5) ;
E=zeros(size(z));
Q=1e-10;
%Creating a matrix containing position vectors for the 100 points on the z-axis
rz=linspace(-0.5,0.5) ;
rx=zeros(size(rz)) ;
ry=zeros(size(rz)) ;
r=[rx ; ry ; rz] ;
%Assigning variables to the position vectors
syms x [100 1]
for i=1 : 100
x(i)=transpose(r(: , i)) ;
end
%Creating a matrix containing position vectors for the 100 points on the y-axis
r1y=linspace(-0.5,0.5) ;
r1z=zeros(size(r1y)) ;
r1x=zeros(size(r1y)) ;
r1=[r1x ; r1y ; r1z] ;
%Assigning variables to the position vectors
syms x1 [100 1]
for i=1 : 100
x1(i)=transpose(r1(: , i)) ;
end
%Calculating distance between the points on z-axis and y-axis
for m=1 : 100
xi(m)=norm(x(m) - x1(m)) ;
end
E=zeros(z) ;
for m=1:100
E(m)=k*Q / abs(xi(m)) ^ 2 ;
end
%Analytical calculation and plotting graph of the solution
cons=1/(2*pi*8.542e-12)*1e-10 ;
y(1,1:100) = cons./abs(z) ;
plot(z,y,"red") ;
%Plotting graph of the solution obtained through code
hold on ;
box on ;
grid on ;
plot(z,E,"*") ;
xlabel('Distance h') ;
ylabel('Magnitude of E') ;
ERROR
Unable to perform assignment because the left and right sides have a different number of elements in assigning position vectors part.
THIS IS MY CODE PLEASE SUGGEST POSSIBLE CORRECTIONS
댓글 수: 2
Alan Weiss
2021년 12월 9일
What errors are you getting? What is the specific issue? Please indicate exactly what you need help with.
Alan Weiss
MATLAB mathematical toolbox documentation
Dyuman Joshi
2021년 12월 9일
Extending Alan's comment - Your syntax is wrong in many places, not sure if that's because you have copy-pasted your code. Correct it and then mention what problems you are facing.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Choose a Solver에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
