Borrar filtros
Borrar filtros

How do I write a function with multiple out puts and inputs with varying times?

1 visualización (últimos 30 días)
For my question I have to write a function that will calculate the outputs of Vr and Vc in a series circuit. Im not even to sure on the equations to calculate this but i believe they are Vr = V*exp(-t/R*C) Vc = V*(1-exp(-t/R*C))
I have written the function as:
function [Vr, Vc] = RC(V, R, C, t)
Vr = V*exp(-t/R*C);
Vc = V*(1-exp(-t/R*C));
end
I then created a new script 'testRC.m' and wrote:
clear;
clc;
V = 9;
R = 4.7;
C = 220;
t = 0:5;
[Vr, Vc] = RC(V, R, C, t);
When I run the function I do not get the expected answer. Any help on this would be extremely appreciated as I am very new to matlab and need help, thanks in advance
  1 comentario
Adam
Adam el 28 de Oct. de 2014
What do you mean by not the expected answer? Is it just incorrect maths or as your question title suggests are you not getting the right number of outputs?
When I quickly pasted your code in I get the two outputs you say you want and the input argument went in fine. I know nothing about series circuits to say if it is the correct answer, but if that is your question I would suggest you reword the question title a little.

Iniciar sesión para comentar.

Respuesta aceptada

Hugo
Hugo el 28 de Oct. de 2014
The problem is in the equation. The constant for the charge of the capacitor is R*C. Therefore, instead of writing
Vc = V*(1-exp(-t/R*C));
you should write
Vc = V*(1-exp(-t/ (R*C) ));
Notice the brackets around R*C.
Same thing in the other equations.
Hope this helps.
  1 comentario
Jim Hamill
Jim Hamill el 28 de Oct. de 2014
Thanks very much, I am now only getting the answers for Vr displayed in the command window, do you know how I can have both output answers displayed?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by