File: ef230-2023-08/www/examples/plotcurves.m Download
%| Plot a set of equations - interactive
function varargout = plotcurves(varargin)
% W. Schleter Fall, 2012

res = {'0','5','x^2','exp(x)/x','42*(sin(x)+sin(x+1))',''};
prompts = {'Lower x','Upper x','f(x)', 'f(x)', 'f(x)','f(x)'};

pcfig = figure;
while 1
    res = inputdlg(prompts,'Curve Plots',1,res);
    if isempty(res)
        close(pcfig);
        return;
    end

    clf
    limits = [str2num(res{1}), str2num(res{2})];
    hold all;
    x=linspace(str2num(res{1}),str2num(res{2}),200);
    leg = {};
    for i=1:4
        functext = res{2+i};
        if length(functext)==0, continue, end;
        try
            f = inline(vectorize(functext),'x');
            y=f(x);
            plot(x,f(x));
            leg{end+1}=functext;
        catch
            waitfor(errordlg(['Error plotting ' functext]))
        end
    end
    legend(leg)
    xlabel('x')
    ylabel('f(x)')
    title('Simple Curve Plots');
end
end % plotcurves