How can I plot these functions?

6 vues (au cours des 30 derniers jours)
John
John le 11 Avr 2014
Modifié(e) : Mischa Kim le 11 Avr 2014
I am trying to plot the frequency and duty cycle of a 555 timer's output, I have already calculated the equations I am trying to plot but I get an error whenever I try to actually plot them. The x axis needs to be logarithmic, and represents a varying resistor in the 555 timers outer circuitry. It goes from 1k to 100k ohms. Ra is another resistor set to 1k, and c is also constant. Here is my code:
ra = 1000; %constant first resistor
x = 1000:100:100000; %Rb from 1000 to 100,000 in increments of 100
c = .000000047; %constant capacitors capacitance
figure; %creates the plot window
y1 = 1/((ra+x)*c + (x*c)); % 1/T is the frequency
y2 = ((ra+x)*c)/((ra+x)*c + (x*c)) * 100; %duty cycle which is = charge time / T * 100%
semilogx(x,y1);
semilogx(x,y2);
legend('Frequency, Hz','Duty Cycle in %');
xlabel('Rb in Ohms');
title('555 timer graph');
the error that I get is:
>> fiveFiveFive Error using / Matrix dimensions must agree.
Error in fiveFiveFive (line 13) y1 = 1/((ra+x)*c + (x*c)); % 1/T is the frequency

Réponse acceptée

Mischa Kim
Mischa Kim le 11 Avr 2014
Modifié(e) : Mischa Kim le 11 Avr 2014
John, use dot-operators ( element-wise division) instead
y1 = 1./((ra+x)*c + (x*c));
y2 = ((ra+x)*c)./((ra+x)*c + (x*c)) * 100;
Notice the period in front of the division operators.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by