フィルターのクリア

Using for loops in MATLAB?

1 回表示 (過去 30 日間)
Nick Haufler
Nick Haufler 2015 年 11 月 6 日
コメント済み: Image Analyst 2015 年 11 月 10 日
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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by