Question: Given the 5 functions ( f 1 - f 5 ) , and the live script provided, write a script to plot all the functions

Given the 5 functions (f1-f5), and the live script provided, write a script to plot all the functions as shown in the live script.
f1:
function [y]= f1(x)
% x is a scalar, and y is a scalar
if length(x) ~=1
error('x is wrong dimensions')
end
y =482.1*x^2+ x^3-42.356;
end
f2:
function [y]= f2(x)
% x is a scalar, and y is a vector
if length(x) ~=1
error('x is wrong dimensions')
end
y =[x*3; x+2];
end
f3:
function [y]= f3(x)
% input is a scalar, output is a vector
if length(x) ~=1
error('x is wrong dimensions')
end
y =[x*15; x+20; 0.5* x^3-10* x];
end
f4:
function [y]= f4(x)
% x is a vector of dimension 2(2x1), y is a vector of dimension 2
if size(x,1) ~=2
error('x is wrong dimensions')
end
A =[3*x(1,1),2*x(2,1); x(2,1)+ x(2,1), x(1,1)^2-2];
y = A * x;
end
f5:
function [y]= f5(x)
% x is a vector of dimension 2, y is a vector of dimension 3
if length(x) ~=2
error('x is wrong dimensions')
end
A =[3*x(1,1),2*x(2,1); x(1,1)+ x(2,1), x(1,1)^2-2; 3/x(2,1), x(1,1);];
y = A * x;
end
Live script:
HW1
clf;
clear;
Load up the data
nGridPts=20;
f1
[x1,y1]= FunctionSampler (@f1,0,10,12);
DataPlotter (x1,y1);
f2
[x2,y2]= FunctionSampler (@f2,0,15,12);
DataPlotter (x2,y2);
f3
[x3,y3]= FunctionSampler (@f3,0,10,12);
DataPlotter (x3,y3);
f4
[x4,y4]= FunctionSampler (@f4,[0;0],[10;20],10);
DataPlotter (x4,y4);
f5
[x5,y5]= FunctionSampler (@f5,[0;0],[10;20],12);
DataPlotter(x5,y5);
All two-dimensional functions (x has two dimensions) should be plotted in a contour plot (f4 and f5). All one-dimensional functions should be in line or scatter plots (f1-f3).
 Given the 5 functions (f1-f5), and the live script provided, write

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!