Ask your own question, for FREE!
Mathematics 24 Online
OpenStudy (raffle_snaffle):

Matlab

OpenStudy (raffle_snaffle):

% Many games require the player to roll two dice. The number on each % die can vary from 1 to 6. % (a) Use the rand function in combination with a rounding function % to create a simulation of one roll of one die. roundnumbers = ceil(6*rand()) % (b) Use your results from part (a) to create a simulation of the % value rolled with a second die. % roundnumbers2 = % (c) Add your two results to create a value representing the total % rolled during each turn. % (d) Use your program to determine the values rolled in a favorite % board game, or use the game shown in Figure P3.20. %% 3.23 % Impedence is related to the inductance, l, and the capacitance, C % by the following equation Z_c = 1/omega*c*j and Z_i = omega*L*j. % For a circuit similar to the one show in Figure P3.22 assume the % following: % C = 1 microF % L = 200 mH % R = 5 ohms % f = 12kHZ % omega = 2*pi*f % V = 10 volts c = 1e-6; % micro-farads L = 200e-3; % milli-hengrys Z_R = 5; % ohms f = 12e3; % kilo Hertz omega = 2*pi*f; % angular frequency V = 10; % volts in the circuit % (a) Find the impedence for the capacitor (Z_c) and for the % inductor (Z_l). Z_C = 1/omega*c*1i; % impedence for capacitor Z_L = omega*L*1i; % impedence for inductor % (b) Find the total impedance Z_T = Z_C + Z_L + Z_R Z_T = Z_C + Z_L + Z_R % (c) Find the current by solving Ohm's law for I. V = I*Z_T I = V/(Z_T) % (d) Electrical engineers often describe complex parameters using % polar coordinates, that is, the paremeter has both an angle and a % magnitude. (Imagine plotting a point on the complex plane, where % the x-axis represnts the real part of the number.) Use the abs % function to find the magnitude of the current found in part c, and % use the angle function to find the corresponding angle.

OpenStudy (raffle_snaffle):

3.23 I am just wanting my work looked over

OpenStudy (raffle_snaffle):

for some reason it won't run and i don't see anyting wrong.

OpenStudy (raffle_snaffle):

@jtvatsim

OpenStudy (jtvatsim):

OK, sorry to keep you waiting... were looking at impedance now?

OpenStudy (jtvatsim):

3.23 looks like its running fine for me.

OpenStudy (raffle_snaffle):

back.

OpenStudy (unklerhaukus):

``` %% 3.23 % Impedance is related to the inductance L, and the capacitance C % by the following equations: % Z_L = i*w*L, Z_C = 1/(i*w*c) % % For a circuit similar to the one show in Figure P3.22 assume the % following: % V = 10 volts, f = 12 kHz, L = 200 mH, C = 1 uF, R = 5 ohm % V = 10; % voltage f = 12e3; % frequency w = 2*pi*f; % angular frequency L = 200e-3; % inductance C = 1e-6; % capacitance Z_R = 5; % resistive impedance %% (a) Find the impedance for the capacitor Z_C, and the inductor (Z_L). % Z_L = i*w*L; % inductive impedance Z_C = 1/(i*w*C); % capacitive impedance %% (b) Find the total impedance Z_T = Z_C + Z_L + Z_R % Z_T = Z_C + Z_L + Z_R; % total impedance %% (c) Find the current by solving Ohm's law for the current. V = I*Z_T % I = V/(Z_T); % current ```

OpenStudy (raffle_snaffle):

^That is what i have... I am running this in a script.

OpenStudy (unklerhaukus):

``` Z_C = 1/(i*w*C); % capacitive impedance ```

OpenStudy (unklerhaukus):

parentheses are necessary on this line

OpenStudy (raffle_snaffle):

% Impedence is related to the inductance, l, and the capacitance, C % by the following equation Z_c = 1/omega*c*j and Z_i = omega*L*j. % For a circuit similar to the one show in Figure P3.22 assume the % following: % C = 1 microF % L = 200 mH % R = 5 ohms % f = 12kHZ % omega = 2*pi*f % V = 10 volts c = 1e-6; % micro-farads L = 200e-3; % milli-hengrys Z_R = 5; % ohms f = 12e3; % kilo Hertz omega = 2*pi*f; % angular frequency V = 10; % volts in the circuit % (a) Find the impedence for the capacitor (Z_c) and for the % inductor (Z_l). Z_C = 1/(i*omega*c); % impedence for capacitor Z_L = omega*L*1i; % impedence for inductor % (b) Find the total impedance Z_T = Z_C + Z_L + Z_R Z_T = Z_C + Z_L + Z_R % (c) Find the current by solving Ohm's law for I. V = I*Z_T I = V/(Z_T)

OpenStudy (unklerhaukus):

is it working like you expect?

OpenStudy (raffle_snaffle):

no it's not working

OpenStudy (raffle_snaffle):

it works in the command window

OpenStudy (unklerhaukus):

what error are you getting?

OpenStudy (raffle_snaffle):

error on anothre line of code. I have like 10 problems on one script but I am separating by cell

OpenStudy (raffle_snaffle):

Undefined function or variable 'thermocouple'. Error in Homework2 (line 138) thermocouple; % array of data thermocouple 1, 2, and 3

OpenStudy (raffle_snaffle):

^that is another problem

OpenStudy (raffle_snaffle):

>> c = 1e-6; % micro-farads L = 200e-3; % milli-hengrys Z_R = 5; % ohms f = 12e3; % kilo Hertz omega = 2*pi*f; % angular frequency V = 10; >> >> Z_C = 1/(i*omega*c); % impedence for capacitor Z_L = omega*L*1i; % impedence for inductor % (b) Find the total impedance Z_T = Z_C + Z_L + Z_R Z_T = Z_C + Z_L + Z_R Z_T = 5.0000e+00 + 1.5066e+04i >>

OpenStudy (raffle_snaffle):

that is in the command window though.

OpenStudy (unklerhaukus):

How can I help you?

OpenStudy (raffle_snaffle):

why doesn't run on the script?

OpenStudy (raffle_snaffle):

haha it runs now

OpenStudy (unklerhaukus):

good.

OpenStudy (raffle_snaffle):

% Many games require the player to roll two dice. The number on each % die can vary from 1 to 6. % (a) Use the rand function in combination with a rounding function % to create a simulation of one roll of one die. roundnumbers = ceil(6*rand()) % (b) Use your results from part (a) to create a simulation of the % value rolled with a second die. % roundnumbers2 = % (c) Add your two results to create a value representing the total % rolled during each turn. % (d) Use your program to determine the values rolled in a favorite % board game, or use the game shown in Figure P3.20.

OpenStudy (raffle_snaffle):

so how would I go about solving part b c and d?

OpenStudy (unklerhaukus):

`roll_1 = ceil(6*rand())` `roll_2 = ceil(6*rand())` `sum = roll_1 + roll_2`

OpenStudy (raffle_snaffle):

so rand() just makes a NxN matrix? That is all it does?

OpenStudy (unklerhaukus):

or maybe `roll_1 = round(6*rand())`

OpenStudy (unklerhaukus):

``` >> help rand ``` rand Uniformly distributed pseudorandom numbers. R = rand(N) returns an N-by-N matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval(0,1). rand(M,N) or rand([M,N]) returns an M-by-N matrix. rand(M,N,P,...) or rand([M,N,P,...]) returns an M-by-N-by-P-by-... array. rand returns a scalar. rand(SIZE(A)) returns an array the same size as A. Note: The size inputs M, N, P, ... should be nonnegative integers. Negative integers are treated as 0. R = rand(..., 'double') or R = rand(..., 'single') returns an array of uniform values of the specified class. The sequence of numbers produced by rand is determined by the settings of the uniform random number generator that underlies rand, RANDI, and RANDN. Control that shared random number generator using RNG.

OpenStudy (raffle_snaffle):

okay what about part d? I can upload the figure if you give me a sec

OpenStudy (raffle_snaffle):

OpenStudy (raffle_snaffle):

roll_3 = ceil(30*rand())

OpenStudy (unklerhaukus):

`ceil` and `round` work the same for positive numbers, the question specifically asks you to use `round`

OpenStudy (raffle_snaffle):

so instead of using ceil use round?

OpenStudy (unklerhaukus):

oh wait a minute `round` and `ceil` are a bit different.

OpenStudy (raffle_snaffle):

so when we used roll_1 = ceil(6*rand()) the six indicates 6 sides on the dice?

OpenStudy (raffle_snaffle):

That is the reason why we are multiplying by rand()?

OpenStudy (unklerhaukus):

yeah, rand function will return a number in the range (0, 1) (an open range)

OpenStudy (unklerhaukus):

we want [1, 6] so we multiply by 6 and the round up

OpenStudy (raffle_snaffle):

okay I see.

OpenStudy (unklerhaukus):

`roll_3 = ceil(30*rand())` == `roll_3 = ceil(30*`(0,1)`)` == `roll_3 = ceil(` (0, 30) `)` == `roll_3 =` [1,30]

OpenStudy (raffle_snaffle):

@UnkleRhaukus what are you doing there? Are those all equal to each other?

OpenStudy (reemii):

\(\verb+ceil(6 * rand())+\) -> \(\verb+rand()+\)creates a random value between 0 and 1, -> then multiplies it by 6, (number is in \((0,6)\)) -> rounds it to above integer. (number is in \(\{1,2,\dots,6\}\). It would be a good idea to create function "rolldie" that you can call any time you want. ``` function result = rolldie() result = ceil(....); end ``` If you want several results now, you just call \(\verb+rolldie()+\) several times. You can also construct games using this function, e.g. ``` function result = mygame() d1 = rolldie(); d2 = rolldie(); result = ....... % do something with d1 and d2 end ```

OpenStudy (unklerhaukus):

yeah

OpenStudy (raffle_snaffle):

@reemii okay thanks

OpenStudy (raffle_snaffle):

@UnkleRhaukus so how would I use round instead of ceil? You said they are a bit different from each other.

OpenStudy (unklerhaukus):

i think `ceil` is more appropriate that `round` here

OpenStudy (unklerhaukus):

*than

OpenStudy (raffle_snaffle):

@UnkleRhaukus okay sounds good. I think the last part on 3.23 I have figured it out.

OpenStudy (reemii):

It is \(possible\) to use \(\verb+round+\) here but you must choose the right transformation of \(\verb+x=rand();+\). Make sure that \(\verb+round+\) is applied in such a way that: - the values returned are really 1,2…,6 - the probability that 1 is returned = the probability that 2 is returned = \(\dotsb = \dfrac16\). If you use \(\verb+round(6 * rand())+\), it will be incorrect: the value 0 will be returned if \(\verb+6*rand()+ < 0.5\). The correct way to do this is: \(\verb$result = round(0.5 + 6 * rand())$\) because 0.5 * 6*rand() will map (0,1) onto (0.5, 6.5) and round( will send any number of (0.5,1.5) onto 1, any number of (1.5,2.5) onto 2, etc.

OpenStudy (reemii):

*typo in last sentence*: because \(\verb$0.5 + 6 * rand()$\) will map ....

OpenStudy (raffle_snaffle):

Okay I am out. @reemii and @UnkleRhaukus thank you for your help. If I have any other question regarding MATLAB I will ask. Night

OpenStudy (reemii):

yw. ciao

OpenStudy (unklerhaukus):

g'night!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!