Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started