Using for loops in MATLAB?

1 visualizzazione (ultimi 30 giorni)
Nick Haufler
Nick Haufler il 6 Nov 2015
Commentato: Image Analyst il 10 Nov 2015
I am stuck on part d in the attached document, my histogram is not coming out right at all. Could someone please help me? I attached my code.

Risposta accettata

Geoff Hayes
Geoff Hayes il 6 Nov 2015
Nick - if you have everything working up to part d, then why have you commented out part b?
As for part d, look closely at what your assignment requires:
Set up a for loop that: repeats 10000 times, and computes random values for resistor 1 and resistor 2 using the randn function as follows:
resistor_value = nominal_value + range/2*randn(1);
where resistor_value is the randomly computed value for the resistor, nominal_value is the expected value for the resistor, and range is the product of the tolerance for the resistor and the nominal resistor value. Stores the voltages on resistors 1 and 2 in vectors counts the number of circuits that do not meet the voltage tolerances.
So you need two arrays of size 10000x1 for each resistor. You will create a for loop that, on each iteration of the loop, will generate two values according to the above equation for each resistor. You will take these two values and determine a voltage for each resistor which you will store in the two arrays.
Presumably you are doing the above for each of the two trials described in step c, so you will have the appropriate nominal/expected value and tolerance that will be used in the above equation. The voltage source, along with the two resistor values, will be used to determine the voltage for each resistor.
Then use hist or histogram to create the histogram given the voltages for each resistor.
  24 Commenti
Nick Haufler
Nick Haufler il 10 Nov 2015
You're totally right, the tolerances were changed, but I didn't divide by 100. I divided by 100 in part b, but just totally forgot. I feel so stupid, but thanks for taking the time to help me with this. I'll finish up the if statements on whether the circuits meet the voltage tolerances to end it. Thanks again!
Image Analyst
Image Analyst il 10 Nov 2015
Nick, you can also "Thank" him by "Accepting his answer and Voting for his answer to give him "reputation points".

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 6 Nov 2015
You did not store the voltages in a vector like it told you to in Part D.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by