int() commant doesn't work for me

12 views (last 30 days)
Ömer
Ömer on 9 Mar 2020
Answered: Steven Lord on 9 Mar 2020
clc
syms x s t
format short g
R=2;
L=20*10^(-6);
C=0.28*10^(-6);
V=40;
tn=13*10^(-6);
%Il=(V/R)*(1-exp((-R*tn)/L))
Il=14.5493641393197;
Vl=V*exp((-R*tn)/L);
M=(40/s)+(L*Il);
N=R+(s*L)+(1/(s*C));
Lap_2=M/N;
l_2=ilaplace(Lap_2);
l_pre=vpa(l_2)
v_int=int(l_2)
I managed to find i(t) of a RLC curcuit. But attempts of turning that equation to its integral form fail with error.
Error using sym/subsindex (line 769)
Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of
the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.
Error in sym/subsref (line 814)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in laplace_2 (line 21)
v_int=int(l_2)

Answers (2)

Star Strider
Star Strider on 9 Mar 2020
When I try to run the code you poisted, I get:
Unrecognized function or variable 'bt'.
Error in ...
k_2=I0/(C*bt);
So while I have no idea what ‘l_2’ is, if it has more than one symbolic variable, for both indefinite and definite integrals, that must be the second argument of the int call. To integrate it within limits, those must be provided as well.
  2 Comments
Ömer
Ömer on 9 Mar 2020
I edit the question. And by the way, when i clear the memory of matlab, int() code was worked.
Star Strider
Star Strider on 9 Mar 2020
In your re-posted code, the int call now works, returning a function of ‘t’ only:
v_int =
(16515726082045475225*30783948672051674253928624877492590735^(1/2)*sin((400*30783948672051674253928624877492590735^(1/2)*t)/5289050460814003)*exp(-50000*t))/2748566845718899299533072648279413649047552 - (26445252304070015*cos((400*30783948672051674253928624877492590735^(1/2)*t)/5289050460814003)*exp(-50000*t))/2361183241434822606848

Sign in to comment.


Steven Lord
Steven Lord on 9 Mar 2020
At some point before you ran that code, I'm pretty sure you had created a symbolic variable named int. When you tried to call the int function, because the variable existed it was instead treated as an attempt to index into the variable. Variables take precedence over functions. The fact that after you called clear it worked supports that hypothesis.
Don't create variables with the same name as functions you want to call.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!