error because "pkg load symbolic"

79 次查看(过去 30 天)
I try to run this code that my teacher gave me, but I can't because it shows an error on line 2
close all; clear all; clc;
pkg load symbolic
syms w t
A=25;
T=3.5;
f1 = A*(heaviside(t)-heaviside(t-T/3));
f2=(2*A/3)*(heaviside(t-T/3)-heaviside(t-2*T/3));
f3=(A/3)*(heaviside(t-2*T/3)-heaviside(t-T));
f=f1+f2+f3;
% Octave Solution:
Fw(w)=fourier(f)
w0=42;
Fww0=round(eval(Fw(w0))*1000)/1000;
-----------------------------------
I get this error:
Unrecognized function or variable 'pkg'.
Error in www (line 2)
pkg load symbolic

回答(2 个)

Walter Roberson
Walter Roberson 2022-12-7
That code is not MATLAB code; it is Octave code. For MATLAB comment out
pkg load symbolic
Note:
Fww0=round(eval(Fw(w0))*1000)/1000;
eval() of a symbolic expression tends to fail in MATLAB. Use double(subs(EXPRESSION)) instead of eval(EXPRESSION)

Torsten
Torsten 2022-12-7
In MATLAB, you don't need to load a package:
pkg load symbolic
This is an octave command.
In MATLAB, either you have a licence for the symbolic toolbox or not. In the first case, your code will run, else not.

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by