How to write the following equation using matlab

Hi I would like to know how i should write the following equation in matlab. The equation will be used to sketch a graph but the correct graph is not being sketched and i feel like it has something to do with the way I wrote the equation. Could anyone please help me out

3 commentaires

Torsten
Torsten le 21 Sep 2022
And how did you write the equation ?
Jadida
Jadida le 22 Sep 2022
This is how I wrote my equation:
h = ((2*sin(((4*L-C*R^2)^0.5)*t/(L*(2*C)^0.5)))/((C^0.5)*(4*L-C*R^2)^0.5)).*(exp((-1*R*t)/(2*L)));
and this is the array t:
t = 0:0.0000001:0.003;
Torsten
Torsten le 22 Sep 2022
Modifié(e) : Torsten le 22 Sep 2022
L = 1;
C = 1;
R = 1;
t = 0:0.0000001:0.003;
h = 2 * sin( sqrt(4*L-C*R^2)*t/(L*sqrt(2*C)) ) / (sqrt(C)*sqrt(4*L-C*R^2)) .* exp(-R*t/(2*L));
plot(t,h)

Connectez-vous pour commenter.

Réponses (1)

syms U L C R t
h(t) = 2*sin(sqrt(U*L - C*R^2)/(L*sqrt(2*L))*t) / (sqrt(C)*sqrt(4*L-C*R^2)) * exp(-t*(R/2*L))
h(t) = 
Unfortunately you have to look very closely to see that the exponent is negative; I will remind Mathworks again that the negative exponent needs to be more clear.
You would need specific numeric values for C L R U in order to be able to plot this.

7 commentaires

What aspect of this answer did not work for you? I compared the result above to your formula image, and they match exactly -- unless, that is, you have particular reason to want sqrt(L)*L to be expressed in that form instead of the mathematically equivalent L^(3/2)
If you need to plot it at particular given times, then I suggest subs() of the constants into the formula, and then matlabFunction() to generate an anonymous function that you can use to evaluate the formula at particular time.
If you do not need to plot it at particular given times, just a time array, then I suggest subs() of the constants into the formula, and then fplot()
Well my equation was pretty much the same and I wasnt getting the correct graph as the output. Also I realised when I substituted the values of R, C, L into the equation I got a complex number as my answer and that could probably be the reason as to why my graph isnt correct. Could you maybe help with this issue please?
This is my code:
R = 10000;
L = 0.01;
C = 0.000000033;
t = 0:0.0000001:0.003;
h = 2*sin(sqrt(4*L - C*R^2)*t/(L*sqrt(2*C)))/(sqrt(C)*sqrt(4*L - C*R^2)) .*exp(-t.*(R/2*L));
plot(t,h)
As you can easily see from your choice of parameters for R,L and C, the expression 4*L - C*R^2 becomes negative.
R = 10000;
L = 0.01;
C = 0.000000033;
4*L - C*R^2
ans = -3.2600
This means that sqrt(4*L - C*R^2) becomes a complex number.
Further according to your graphics,
exp(-t.*(R/2*L))
should be
exp(-R*t/(2*L))
Sam Chak
Sam Chak le 23 Sep 2022
Modifié(e) : Sam Chak le 23 Sep 2022
This part is definitely not the same
Yours is , because R is divided by 2 first, and then is multiplied with L.
Your graph blows up is because the value of the capacitance C is super small. Division by a very small value leads to ...
Jadida
Jadida le 24 Sep 2022
well I did do it with Torsten's answer but it still gives me the same graph
Torsten
Torsten le 24 Sep 2022
Modifié(e) : Torsten le 24 Sep 2022
The same graph compared to which graph ?
As I said, sqrt(4*L-C*R^2) becomes complex-valued for your parameter value for L, C and R.
You will have to change them or alternatively plot real(h), imag(h) or abs(h).
Jadida, I'd suggest you show us the ordinary differential equation of RLC circuit.
We can probably use dsolve to verify if the analytical solution is the same as the equation provided by you.

Connectez-vous pour commenter.

Question posée :

le 21 Sep 2022

Commenté :

le 24 Sep 2022

Community Treasure Hunt

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

Start Hunting!

Translated by