MATLAB Answers

Unrecognized function or variable

68 views (last 30 days)
Joshua Primeaux
Joshua Primeaux on 8 Feb 2021
Commented: Joshua Primeaux on 8 Feb 2021
syms t
x(t) = piecewise (t>=0, sin(3*t), t>=2*pi, sin(3*t)^2, t>3*pi,0);
t1 =0:0.1:3*pi;
x=subs(x,t,t1);
plot(t1,x)
xlabel('Time')
ylabel('x(t)')
disp('Energy of x(t)')
Energy of x(t)
I1 = int(sin(3*t)^2);
I2 = int(sin(3*t)^4);
E = I1(2*pi)-I1(0)+I2(2*pi)-I2(3*pi)
Energy of x(t)
Unrecognized function or variable 'Energy'.
This is my code I'm not sure why it is saying unrecognized function any help would be appreciated thank you.

Answers (2)

Steven Lord
Steven Lord on 8 Feb 2021
I suspect you copied and pasted what had been typed and/or displayed in the Command Window (including the text that your disp call displayed, namely "Energy of x(t)") into a file in the Editor/Debugger and tried to run it. You'll need to delete or comment out the displayed text in the file in the Editor/Debugger..
  1 Comment
Joshua Primeaux
Joshua Primeaux on 8 Feb 2021
ok I fixed that now I'm getting
syms t
x(t) = piecewise (t>=0, sin(3*t), t>=2*pi, sin(3*t)^2, t>3*pi,0);
t1 =0:0.1:3*pi;
x=subs(x,t,t1);
plot(t1,x)
xlabel('Time')
ylabel('x(t)')
disp('Energy of x(t)')
I1 = int(sin(3*t)^2);
I2 = int(sin(3*t)^4);
E = I1(2*pi)-I1(0)+I2(2*pi)-I2(3*pi)
Index exceeds the number of array elements (1).
Error in sym/subsref (line 902)
R_tilde = builtin('subsref',L_tilde,Idx);

Sign in to comment.


madhan ravi
madhan ravi on 8 Feb 2021
Following Steven’s answer would clear that error but you will have a following error, so change that part of your code to the following:
%Energy of x(t)
I1(t) = int(sin(3*t)^2);
I2(t) = int(sin(3*t)^4);
E = I1(2*pi)-I1(0)+I2(2*pi)-I2(3*pi)
%Energy of x(t)

Community Treasure Hunt

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

Start Hunting!