Docsity

Solution to H.W. Set 9, Problem 2: Plotting the Magnitude of a Complex-Valued Function - P, Assignments of Engineering

Toggle sidebar
bg1
AOE/ESM 2074
H.W. Set 9 - Solution
[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 + j*om)./(144 - om.^2 + 12*j*om); % 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:
1
pf2

Partial preview of the text

Download Solution to H.W. Set 9, Problem 2: Plotting the Magnitude of a Complex-Valued Function - P and more Assignments Engineering in PDF only on Docsity!

AOE/ESM 2074

H.W. Set 9 - Solution

[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