

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solution to problem 2 of homework set 9, which involves plotting the magnitude of a complex-valued function using matlab. The function t(ω) is given by the equation in the document, and the script provided generates semilog and log-log plots of the function's amplitude over the frequency range 0.1 to 10 radians per second.
Typology: Assignments
1 / 2
This page cannot be seen from the preview
Don't miss anything!


[2.] We are to plot the magnitude of the complex-valued function
T (ω) =
12(12 + ω) 144 − ω^2 + 12 ω
evaluated over the range. 1 ≤ ω ≤ 10. A Matlab script to do this is:
% Script for HW Problem 2 on HW Set 9 % om = logspace(-1,2,101); % 101 points for omega % T = 12(12 + jom)./(144 - om.^2 + 12jom); % evaluate the complex-valued function % subplot(2,1,1) semilogx(om,abs(T)) xlabel(’Frequency (r/s)’) ylabel(’Amplitude’) title(’\bf Semilog plot of Force amplification’) grid on % subplot(2,1,2) loglog(om,abs(T)) xlabel(’Frequency (r/s)’) ylabel(’Amplitude’) title(’\bf Log-Log plot of Force amplification’) grid on %
Running this code produces the following figure:
100 -1^100 101
1
Frequency (r/s)
Amplitude
Semilog plot of Force amplification
(^1010) -1 100 101 102
100
101
Frequency (r/s)
Amplitude
Log-Log plot of Force amplification
[3.] We are to read in a character string and then test for the occurrences of a given character in that string. Here is a sample code to implement this procedure:
% Script for Prob3 on H.W. Set 9 str_in = input(’Please supply a character string. \n’,’s’); % c = ’ab’; while length(c) > 1 c = input(’Please supply a single character : ’,’s’) end % % Now look for the occurrences of the character within the string % num_c = sum(length(findstr(str_in,c))); % fprintf(’ The character %c appears %i times in the string, \n %50s \n’,c,num_c,str_in);
Running this code from the Matlab prompt produces the following response:
prob_ Please supply a character string. This is a test Please supply a single character : i c = i The character i appears 2 times in the string, This is a test