Overall Assignment For this assignment you are to write a simple computer progra
ID: 3688080 • Letter: O
Question
Overall Assignment
For this assignment you are to write a simple computer program to evaluate a function of 2 variables over a range of input values, using one- and two-dimensional arrays. using MATLAB.
For the X input, your program should read in the minimum value of X, the maximum value of X, and the change in X between data points.
For the Y input, your program should read in the minimum value of Y, the maximum value of Y, and the number of data points desired in the Y direction.
Once you have read in the necessary input and allocated arrays, fill the x and y vectors using the colon operator and linspace( ) respectively.
Then calculate X cos( X ) and Y sin( Y ) using elementwise multiplication and a final result using matrix multiplication
print out the results
Explanation / Answer
· % x = input('enter the input array x(note:matrix multification should possible):')
· x=[1 3;3 8] y=[5 7; 10 9]
· lex=length(x)
% y= input('enter the input array y(note:matrix multification should possible):')
· ley=length(y);
· % max and min values
· minx = min(x(:));
· maxx = max(x(:));
· % changing values
· A=diff(x(:));
· f=diff(y(:));
· fprintf('the change xval=%d ',a);
· fprintf('the change y val=%d ',f);
· fprintf('the min xval=%d ',minx);
· fprintf('the max xval=%d ',maxx);
· % max and min values
· miny = min(y(:));
· maxy = max(y(:));
· fprintf('the min yval=%d ',miny);
· fprintf('the max yval=%d ',maxy);
· % function values
· g=x*cos(x);
· fprintf('the function xval=%d ',g);
· l=y*cos(y); fprintf('the function yval=%d ',l);
· % colon operation
q=[x;y]
· if minx>miny
· d=miny;
· end
if maxx>maxy
· w=maxx;
· else
w=maxy;
· end
· % line space
· linespace= linspace(d,w,w)
· % ranges values
· r=range(g);
· fprintf('the range first function val=%d ',r);
· e=range(l);
· fprintf('the range second function val=%d ',e);
f = (x*cos(x))*(y*sin(y))
r=range(f);
fprintf('the range main function val=%d ',r);
Sample output::
· x = 1 3 3 8 y = 5 7 10 9
· lex = 2 the change xval=1
· the change xval=4
· the change xval=7
· the change xval=2
· the change xval=5
· the change xval=8
· the change xval=3
· the change xval=6
· the change xval=9
· the change y val=5
· the change y val=-3
· the change y val=2
· the min xval=1
· the max xval=8
· the min yval=5
· the max yval=10
· the function xval=-2.429675e+00
the function xval=-6.299033e+00
the function xval=-1.426493e+00
· the function xval=-4.133978e+00
· the function yval=-4.455190e+00
· the function yval=-4.715022e+00
· the function yval=-2.608401e+00
· the function yval=-6.611498e-01
· q = 1 3 3 8 5 7 10 9
· linespace = 1 2 3 4 5 6 7 8 9 10
· the range first function val=3.869358e+00
· the range first function val=2.707485e+00
· the range second function val=2.598321e-01
· the range second function val=1.947251e+00
the range main function val=
72.5063 51.7031
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.