Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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).
image text in transcribed

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

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

3540511717, 978-3540511717

More Books

Students also viewed these Databases questions

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago