%% Mfile for Chapter 12: Troubleshooting

%% Initialization

clear all
close all
format short
set(0,'DefaultAxesFontSize', 16)

%% Conflicting Definitions
plot = gcf;
X = -2:0.1:2;
try
    plot(X, X.^2)
catch err
    disp(err.message)
end

%%
which plot
clear plot
plot(X, X.^2)

%% Arithmetic Operations
9^1/2 - 4/2^2
9^(1/2) - (4/2)^2

%% Wrong Delimiters
X = -1:0.1:1;

%%
% Try the following in the Command Window; syntax error prevents script
% from running even with try/catch wrapper.

%X[1]
%A = (0,1,2)


%%
abs -3

%%
double('-3')

%%
{'a', 'b'}

%%
['a', 'b']

%% Arithmetic Symbols
% Try the following in the Command Window; syntax error prevents script
% from running even with try/catch wrapper.

%2-*4

%% Spelling Errors
try
    arctan(1)
catch err
    disp(err.message)
end

%% Plotting Errors
X = -3:0.01:3;
plot(X, X.^(1/3))
print -deps trouble1.eps

%%
plot(X, sign(X).*abs(X).^(1/3))
print -deps trouble2.eps

%% Debugging Techniques
keyboard

%%
%This file accesses three versions of "shadecurves", the incorrect
%first version in Chapter 11, the second partially corrected version,
%and the third fully corrected version.

shadecurves1(@sin, @(x) -sin(x), 0, pi)
print -deps trouble3.eps

%%
shadecurves(@sin, @(x) -sin(x), 0, pi)
print -deps trouble4.eps

%%
shadecurves1(@(x) x^2, @sqrt, 0, 1)
print -deps trouble5.eps

%%
shadecurves2(@(x) x^2, @sqrt, 0, 1)
print -deps trouble6.eps

%%
shadecurves2(@(x) x^2, @(x) x^4, -1.5, 1.5)
print -deps trouble7.eps

%%
shadecurves3(@(x) x^2, @(x) x^4, -1.5, 1.5)
print -deps trouble9.eps


