a) Write a Matlab script to call the two functions described in parts b) and c)
ID: 3865308 • Letter: A
Question
a) Write a Matlab script to call the two functions described in parts b) and c) below. Your script must erase all workspace variables, clear the command screen, and close any plot figures. Your script creates the inputs for the function described in part b) below. In particular, the input vector r is to be linearly spaced with N = 10^5 points between 1 times 10^-2 lessthanorequalto r lessthanorequalto 1 times 10^0 (meters). b) Write a Matlab function with the filename: coulomb_force.m where: Inputs: r a row vector of strictly increasing positive values (meters), i.e. r(1)Explanation / Answer
b)function F=coulomb_force(r,q,varargin)
if r(1)<0
error('You messed up!')
elseif issorted(r)~=1
error('You messed up!')
else
if nargin==3
er=varargin;
else
er=1;
end
eo=8.987551787368*10^9;
e=eo*er;
ke=1/(4*pi*e);
F=ke*prod(q)./r.^2;
end
c)
function FvsR(F,r)
plot(r,F)
title('F vs r')
xlabel('distance(meter)')
ylabel('force(Newton)')
grid on
a)
clear;
clc;
close all;
r=linspace(10^-2,1,10^5);
q1=input('Enter q1:');
q2=input('Enter q2:');
F=coulomb_force(r,[q1 q2]);
FvsR(F,r)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.