Question: clear all; close all; % Start fresh % Organizing Inputs % f = @ ( x ) sin ( 3 * pi * cos (
clear all; close all; Start fresh
Organizing Inputs
f @x sinpicospixsinpix;
a ; b ; n ;
x linspaceabn; Vector containing initial starting points
q zerossizex; Preallocate a vector for storing roots.
tic
for i:n
qi fzerofxi;
end
ttoc
Processing Outputs
q uniqueq; keep roots with unique values only.
showsavePlot true;
switch showsavePlot
case true
Plot the function and roots if possible
xx linspaceab;
fig figurePosition;
plotxxfxxk'linewidth',;
hold on
plotqfqo'markerfacecolor',r
xlimab; ylim;
yticks
xlabelx; ylabelfx;
pbaspect
printfig'MySavedPlot',dpng
end
Create a parallel pool if none exists
if isemptygcp
parpool;
end
tic
parfor i:n
qi fzerofxi;
end
tp toc
Processing Outputs
q uniqueq; keep roots with unique values only.
q uniquetolqe;
showsavePlot true;
switch showsavePlot
case true
Plot the function and roots if possible
xx linspaceab;
fig figurePosition;
plotxxfxxk'linewidth',;
hold on
plotqfqo'markerfacecolor',r
xlimab; ylim;
yticks
xlabelx; ylabelfx;
pbaspect
printfig'MySavedPlot',dpng
end
speedupttp
eff speedupn
Convert the above code of matlab to python and R
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
