Matlab code for Engineering Physics not working
Show older comments

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 Comments
Alan Weiss
on 9 Dec 2021
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
on 9 Dec 2021
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.
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!