MATLAB Answers

# Unrecognized function or variable

68 views (last 30 days)
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.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Answers (2)

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 CommentShowHide None
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 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)
##### 1 CommentShowHide None
Joshua Primeaux on 8 Feb 2021
Thank you that worked

Sign in to comment.

R2020b

### Community Treasure Hunt

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

Start Hunting!