Input arguments must be 'double'.? Sin, Sawtooth, Square functions.

5 views (last 30 days)
I have this function
% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
a=handles.edit5;
f=handles.edit2;
r1=handles.edit7;
r2=handles.edit8;
c=handles.edit9;
w=2*pi*f;
syms x
xn=0:0.01:2*f;
y=a*sin((w*x));
Y=int(y,x);
z=(-1/(r1*c)).*Y
yn = subs(y, x, xn);
zn = subs(z, x, xn);
axes(handles.axes2)
plot(xn, yn, xn, zn, 'g');
grid on
static= [num2str(-r2/r1) ' v/v'];
set(handles.text5,'String',static);
static2= [num2str((-1/(r1*c))*a*2*f) 'V'];
set(handles.text9,'String',static2);
And it works correctly but when I replace "sin" with "sawtooth" or "square" like this
% --- Executes on button press in radiobutton4.
function radiobutton4_Callback(hObject, eventdata, handles)
a=handles.edit5;
f=handles.edit2;
r1=handles.edit7;
r2=handles.edit8;
c=handles.edit9;
w=2*pi*f;
syms x
xn=0:0.01:2*f;
y=a*sawtooth((w*x));
Y=int(y,x);
z=(-1/(r1*c)).*Y
yn = subs(y, x, xn);
zn = subs(z, x, xn);
axes(handles.axes2)
plot(xn, yn, xn, zn, 'g');
grid on
static= [num2str(-r2/r1) ' v/v'];
set(handles.text5,'String',static);
static2= [num2str((-1/(r1*c))*a*2*f) 'V'];
set(handles.text9,'String',static2);
It gives me this error
Error using proyectoanaloga2>radiobutton4_Callback (line 211)
Input arguments must be 'double'.
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in proyectoanaloga2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)proyectoanaloga2('radiobutton4_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
In that line:
y=a*sawtooth((w*x));
What can I do? Thank you so much.

Answers (1)

Walter Roberson
Walter Roberson on 21 May 2015
sawtooth() is a numeric routine from the Signal Processing Toolbox. You are attempting to pass a symbolic variable in to it, get out some kind of symbolic sawtooth formula, and then do a symbolic integration on the formula. All of which fails because sawtooth() just is not a symbolic routine.
I do not have a symbolic formula for sawtooth available at the moment. Ah, here is one:
PI = sym('PI');
abs(2*x/PI+1-4*floor((1/2)*x/PI+3/4))-1
using sym('PI') is for accuracy.
Do not expect a closed form solution when you integrate

Community Treasure Hunt

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

Start Hunting!