필터 지우기
필터 지우기

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 CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by