2.11 (MATLAB) Fill in the missing lines and then run the program in MATLAB. Note
ID: 2268305 • Letter: 2
Question
2.11 (MATLAB) Fill in the missing lines and then run the program in MATLAB. Note that the functions magvector and unitvector, created in MATLAB 2.1 must be in your work folder for the program to properly run. %Coulomb's Law eo-8.854e-12; %free-space permittivity a1=10e-9;q2-2e-9;%charges in Coulombs Pl= [ 0 0 4);P2-[0 4 0];%q1&q2; location % (a) Find vector RV from q1 to q2. Rvmag=magvec tor (Rv) ;&magnitude; of RV Rvuv=unitvector (Rv);%unit vector of Rv % (b) Find force F12 acting on q2. F12=Explanation / Answer
Hello,
Please find the answer attached as under. Please give a thumbs up rating if you find the answer useful! Have a rocking day ahead!
**** Matlab Code ******
Definition of function magvector:
function mag = magvector(P)
mag = norm(P);
end
Definition of function unitvector:
function v = unitvector(P)
v = P/norm(P);
end
Copy paste the above 2 pieces of code in seperate m files and save them as function files.
Main code :
%%%%%%%%%%%%%%%%%%%%%
%% Force between 2 particles in space
eo = 8.854e-12;
q1 = 10e-9; q2 = 2; % suppress one of the e-9 to avoid round off error in Matlab
P1 = [0 0 4]; P2 = [0 4 0];
Rv = (P2 - P1)';
Rvmag = magvector(Rv);
Rvuv = unitvector(Rv);
F12 = q1*q2/(4*pi*eo*Rvmag*Rvmag) * Rvuv; % you have to multiply e-9 with this answer
fprintf('The required force is (10^-9) * (%fi + %fj + %fk) Newtons ',F12(1),F12(2),F12(3));
**** End of Code *****
Run the above main code after saving the function files.
Output:
The required force is (10^-9) * (0.000000i + 3.972059j + -3.972059k) Newtons
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.