Error using ezplot on differential equation

Hi. Can anyone please tell me what's wrong with this code?
syms ya yb y xb t
ya = dsolve('(L*10^(-3))/(Rs*10^3)*D2ya+Dya+1/(Rs*10^3+C*10^(-6))*ya=0','ya(0)=5','Dya(0)=2');
figure(1)
ezplot(ya,[0,10])
grid on
axis auto
It displays this error message:
Error using sym/ezplot (line 50)
Two variables or less expected when plotting an equation.
Error in soustava (line 14)
ezplot(ya,[0,10])
This code is crucial for me to get working, otherwise I fail my subject. Why it works with older version and R2019a doesn't accept it?

답변 (1개)

Star Strider
Star Strider 2019년 12월 19일

0 개 추천

Provide the correct numerical values for ‘C’, ‘L’, and ‘Rs’ if you want to plot it:
syms C L Rs ya(t) yb y xb t
C = sym(3);
L = sym(5);
Rs = sym(7);
Dya = diff(ya);
D2ya = diff(Dya);
ya = dsolve((L*10^(-3))/(Rs*10^3)*D2ya+Dya+1/(Rs*10^3+C*10^(-6))*ya==0,ya(0)==5,Dya(0)==2)
figure(1)
ezplot(ya,[0,10])
grid on
axis auto

댓글 수: 10

Oh, sorry, you are absolutely correct. I've had to include that portion of code as well:
L = 20; % [mH]
C = 100; % [uF]
Rs = 100; % [kOhm]
These are the numerical values of electrical components including their units in comment.
With those additions, this produces an appropriate plot:
syms C L Rs ya(t) yb y xb t
C = sym(100E-6);
L = sym(20E-3);
Rs = sym(100E+3);
Dya = diff(ya);
D2ya = diff(Dya);
ya = dsolve((L*10^(-3))/(Rs*10^3)*D2ya+Dya+1/(Rs*10^3+C*10^(-6))*ya==0,ya(0)==5,Dya(0)==2)
figure(1)
ezplot(ya,[0,2E-12])
grid on
axis auto
title(['$ya(t)=5.0-4.5475\times 10^{-13}\,{\mathrm{e}}^{-5.0e+12\,t}$'], 'Interpreter','latex')
Marek Polacek
Marek Polacek 2019년 12월 19일
편집: Marek Polacek 2019년 12월 19일
So I need to convert the numeric values to the symbolic expression and then it can be used? I didn't even know that that's necessary. I though that it will do it automatically. Turns out not. Well, thank you. Something new I learn :D
EDIT:
Your code (I've done some changes in order to keep the values correct. because apparently you quite misunderstood how unit translation works) produced new error:
Array indices must be positive integers or logical values.
Error in sym/subsref (line 890)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in soustava (line 14)
ya = dsolve(L/Rs*D2ya+Dya+1/(Rs+C)*ya==0,ya(0)==5,Dya(0)==2);
What is the problem with the units?
My code threw no errors when I ran it. I have no idea where the subsref error comes from.
This code (the new ‘ya’ being the only difference) ran without error:
syms C L Rs ya(t) yb y xb t
C = sym(100E-6);
L = sym(20E-3);
Rs = sym(100E+3);
Dya = diff(ya);
D2ya = diff(Dya);
% ya = dsolve((L*10^(-3))/(Rs*10^3)*D2ya+Dya+1/(Rs*10^3+C*10^(-6))*ya==0,ya(0)==5,Dya(0)==2)
ya = dsolve(L/Rs*D2ya+Dya+1/(Rs+C)*ya==0,ya(0)==5,Dya(0)==2);
figure(1)
ezplot(ya,[0,1])
grid on
axis auto
You must have done something wrong to have triggered that error.
Okay, this is what I tried:
%% Parametry obvodu
L = sym(20E-3); % [mH]
C = sym(100E-6); % [uF]
Rs = sym(100E+3); % [kOhm]
%% Diferenciální rovnice
syms ya yb y xb t
Dya = diff(ya);
D2ya = diff(Dya);
ya = dsolve(L/Rs*D2ya+Dya+1/(Rs+C)*ya==0,ya(0)==5,Dya(0)==2);
figure(1)
ezplot(ya,[0,1])
grid on
axis auto
This is outcome:
Array indices must be positive integers or logical values.
Error in sym/subsref (line 890)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in soustava (line 14)
ya = dsolve(L/Rs*D2ya+Dya+1/(Rs+C)*ya==0,ya(0)==5,Dya(0)==2);
I've literally just copied it over...
You did not copy my syms call. Use this one:
syms ya(t) yb y xb t
and the code works. It is absolutely necessary to declare ‘ya’ as ‘ya(t)’ or the code will fail.
Yeah. It works. Except that the plots don't actually show how the function should look like. Thanks anyway, it definitely helps :)
The plots do, actually.
Consider:
syms C L Rs ya(t) yb y xb t
C = sym(100E-6);
L = sym(20E-3);
Rs = sym(100E+3);
Dya = diff(ya);
D2ya = diff(Dya);
% ya = dsolve((L*10^(-3))/(Rs*10^3)*D2ya+Dya+1/(Rs*10^3+C*10^(-6))*ya==0,ya(0)==5,Dya(0)==2)
ya = dsolve(L/Rs*D2ya+Dya+1/(Rs+C)*ya==0,ya(0)==5,Dya(0)==2);
figure(1)
ezplot(ya,[1E-7,2E-4])
grid on
axis auto
set(gca, 'XScale','log')
It is necessary to either expand or transform the independent variable scale to see the function correctly.
The intended function was actually a filter. It's not a linear function. This is how it should look like:
function_correct.jpg
This is how it actually looks:
function_actual.jpg
I don't think that it should be linear function (or in this case, pretty much constant, when considering those tenthousanths decrements). Look at the top plot - it shows nice band pass filter. Look at the bottom plot - it shows straight line going in super small decrements. The values are also incorrect. The function should be much below the value of 1 (the top is actually decibel range, so it is in logarithmic scale)...
Please note that your differential equation (and of course its solution) are in the time domain and the Bode plot is in the frequency domain. They should not look at all the same.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 12월 19일

댓글:

2019년 12월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by