Borrar filtros
Borrar filtros

Plotting a function not working

1 visualización (últimos 30 días)
Jonathon Mook
Jonathon Mook el 10 de Abr. de 2020
Comentada: Tommy el 11 de Abr. de 2020
Hi.
I'm attempting to plot a function for the Current in a resistor-inductor circuit but am having no success in producing a proper graph. Why is this program not producing a graph with curves and only producing a straight line? Thanks
  2 comentarios
Colo
Colo el 10 de Abr. de 2020
can you show me your code?
Jonathon Mook
Jonathon Mook el 11 de Abr. de 2020
I attached my .m file in the beginning

Iniciar sesión para comentar.

Respuesta aceptada

Tommy
Tommy el 11 de Abr. de 2020
One possible explanation:
b=cos(omega*t*phi);
c=cos(phi)*exp(-t*R/L);
In these lines you use t, which is your upper bound on the time, rather than T, a vector containing each time point. As a result, I is a scalar corresponding to the current at the last time point.
b=cos(omega*T*phi);
c=cos(phi)*exp(-T*R/L);
Using these instead, I will be a vector with the same size as T which contains the current at each time point. If you want to plot current over time, you'll need to flip your arguments to plot:
plot(T, I)
  2 comentarios
Jonathon Mook
Jonathon Mook el 11 de Abr. de 2020
I'm so stupid I didn't see that. That worked fantastic. I'm new to this, but I'm learning. Thanks so much!
Tommy
Tommy el 11 de Abr. de 2020
You're very welcome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by