Using for loops in MATLAB?

1 次查看(过去 30 天)
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.

采纳的回答

Geoff Hayes
Geoff Hayes 2015-11-6
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 个评论
Nick Haufler
Nick Haufler 2015-11-10
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 2015-11-10
Nick, you can also "Thank" him by "Accepting his answer and Voting for his answer to give him "reputation points".

请先登录,再进行评论。

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by