Answered step by step
Verified Expert Solution
Link Copied!

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) sin(3*pi*cos(2*pi*x).*sin(pi*x));
a =-3; b =5; n =4^9;
x0= linspace(a,b,n); % Vector containing initial starting points
q = zeros(size(x0)); % Preallocate a vector for storing roots.
%%%%%%%%%%%%%%%%%%
tic
for i=1:n
q(i)= fzero(f,x0(i));
end
t1=toc
%Processing Outputs%
q = unique(q); % keep roots with unique values only.
showsavePlot = true;
switch showsavePlot
case true
%Plot the function and roots if possible
xx = linspace(a,b,1001);
fig = figure('Position',[1001001200300]);
plot(xx,f(xx),'-k','linewidth',2);
hold on
plot(q,f(q),'o','markerfacecolor','r')
xlim([a,b]); ylim([-1,1]);
yticks([-101])
xlabel('x'); ylabel('f(x)');
pbaspect([411])
print(fig,'MySavedPlot','-dpng')
end
% Create a parallel pool if none exists
if isempty(gcp())
parpool();
end
tic
parfor i=1:n
q(i)= fzero(f,x0(i));
end
tp= toc
%Processing Outputs%
%q = unique(q); % keep roots with unique values only.
q= uniquetol(q,1e-10);
showsavePlot = true;
switch showsavePlot
case true
%Plot the function and roots if possible
xx = linspace(a,b,1001);
fig = figure('Position',[1001001200300]);
plot(xx,f(xx),'-k','linewidth',2);
hold on
plot(q,f(q),'o','markerfacecolor','r')
xlim([a,b]); ylim([-1,1]);
yticks([-101])
xlabel('x'); ylabel('f(x)');
pbaspect([411])
print(fig,'MySavedPlot','-dpng')
end
speedup=t1/tp
eff= speedup/n
Convert the above code of matlab to python and R

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications Dasfaa 2023 International Workshops Bdms 2023 Bdqm 2023 Gdma 2023 Bundlers 2023 Tianjin China April 17 20 2023 Proceedings Lncs 13922

Authors: Amr El Abbadi ,Gillian Dobbie ,Zhiyong Feng ,Lu Chen ,Xiaohui Tao ,Yingxia Shao ,Hongzhi Yin

1st Edition

3031354141, 978-3031354144

More Books

Students also viewed these Databases questions

Question

Use implicit differentiation to find d 2 y/dx 2 if 4x 2 + y 2 = 1.

Answered: 1 week ago

Question

Define span of management or define span of control ?

Answered: 1 week ago

Question

What is meant by formal organisation ?

Answered: 1 week ago

Question

What is meant by staff authority ?

Answered: 1 week ago

Question

Discuss the various types of policies ?

Answered: 1 week ago

Question

identify current issues relating to equal pay in organisations

Answered: 1 week ago