Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help. I\'ve been trying to figure out how to write this code for a proble

ID: 3639296 • Letter: P

Question

Please help. I've been trying to figure out how to write this code for a problem for a week now, and I cannot figure it out.

Q. Write a function in an m-file that meets the requirements listed below. Similar to the gravity field example in class, your function will calculate the voltage, or electric potential, at different points in space caused by point charges. The equation for voltage due to a point charge is (equation) where V is the charge in volts, Q is the charge in Coulombs, r is the distance between the charge and the point in meters, and is 8.85*10-12 C/Vm. Note that voltage is a scalar value, meaning that the voltage at a point in space affected by two point charges is simply the sum of the two separate voltages. Assume that the voltage in space without point charges is 0 volts.

* The first input to your function is the dimension of the field in both the x and y dimensions. You may assume that the input is a valid positive integer.
*The second input to your function is an array with three columns. Each row corresponds to a point charge. Column 1 is the x coordinate, column 2 is the y coordinate, and column 3 is the charge in coulombs.
*The output of your function is a two-dimensional array that is the size specified by the first input. The value at each element should be the total voltage at the point due to the charges given in the second input.

This is what I have:
function[ArrayOutput] = Electricity(dimension, ArrayS)

e0 = 8.85*10^-12;
QCoulombs = 0;
rdistance = 0;
Voltage = (QCoulombs)/(4*pi*e0*rdistance);

And I'm completely clueless about what to write.
Thanks

Explanation / Answer

Fs=48000; %Specify Sampling Frequency Ts=1/Fs; %Sampling period. Ns=512; %Nr of time samples to be plotted. Num = [0.0818 0.1691 -0.0355 0.7979 -0.0355 0.1691 0.0818]; %Numerator Coefficients as generated by fda tool t=[0:Ts:Ts*(Ns-1)]; %Make time array that contains Ns elements %t = [0, Ts, 2Ts, 3Ts,..., (Ns-1)Ts] f1=2400; f2=10000; f3=11500; f4=20000; x1=sin(2*pi*f1*t); %create sampled sinusoids at different frequencies x2=sin(2*pi*f2*t); x3=sin(2*pi*f3*t); x4=sin(2*pi*f4*t); x=x1+x2+x3+x4; %Calculate samples for a 4-tone input signal grid on; N=6; %FIR requires filter order (N) to be EVEN %when gain = 1 at Fs/2. A=1; %FIR filters have no poles, only zeros. B=Num; %Taking Coefficients generated by fda tool for j=1:Ns %Now apply this filter to our 4-tone test sequence sum=0; %Calculating the output using convolution for i=1:7 if((j-i)>0) sum=sum +Num(i)*x(j-i+1); end end y(j)=sum; end subplot(2,1,1); %Two subplots will go on this figure window. Npts=200; plot(t(1:Npts),x(1:Npts)) %Plot first Npts of this 4-tone input signal title('Time Plots of Input and Output'); xlabel('time (s)'); ylabel('Input Sig') subplot(2,1,2); %Now go to bottom subplot. plot(t(1:Npts),y(1:Npts)); %Plot first Npts of filtered signal. xlabel('time (s)'); ylabel('Filtered Sig'); figure; %Create a new figure window, so previous one isn't lost. subplot(2,1,1); xfftmag=(abs(fft(x,Ns))); %Compute spectrum of input signal. xfftmagh=xfftmag(1:length(xfftmag)/2); %Plot only the first half of FFT, since second half is mirror imag %the first half represents the useful range of frequencies from %0 to Fs/2, the Nyquist sampling limit. f=[1:1:length(xfftmagh)]*Fs/Ns; %Make freq array that varies from %0 Hz to Fs/2 Hz. plot(f,xfftmagh); %Plot frequency spectrum of input signal title('Input and Output Spectra'); xlabel('freq (Hz)'); ylabel('Input Spectrum'); subplot(2,1,2); yfftmag=(abs(fft(y,Ns))); yfftmagh=yfftmag(1:length(yfftmag)/2); %Plot only the first half of FFT, since second half is mirror image %the first half represents the useful range of frequencies from %0 to Fs/2, the Nyquist sampling limit. plot(f,yfftmagh); %Plot frequency spectrum of input signal xlabel('freq (Hz)'); ylabel('Filt Sig Spectrum'); this program will give you much detailed analysis for ur problem ..