How can I plot these functions?

2 visualizaciones (últimos 30 días)
John
John el 11 de Abr. de 2014
Editada: Mischa Kim el 11 de Abr. de 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

Respuesta aceptada

Mischa Kim
Mischa Kim el 11 de Abr. de 2014
Editada: Mischa Kim el 11 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by