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 Kommentare

Torsten
Torsten am 21 Sep. 2022
And how did you write the equation ?
Jadida
Jadida am 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;
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)

Melden Sie sich an, um zu kommentieren.

Antworten (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 Kommentare

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 am 23 Sep. 2022
Bearbeitet: Sam Chak am 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 am 24 Sep. 2022
well I did do it with Torsten's answer but it still gives me the same graph
Torsten
Torsten am 24 Sep. 2022
Bearbeitet: Torsten am 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).
Sam Chak
Sam Chak am 24 Sep. 2022
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.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 21 Sep. 2022

Kommentiert:

am 24 Sep. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by