using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU)
1. No Input/No Output
Write a function that has no input and no outputs. This function
will simply display some text when it is called.
(this is my code, are there suggestions for improvements?)
function Display()
disp('some text')
end
2. 1 Input/No Outputs
Write a function with one input and no outputs. This function will
simply display a variable that is provided as an input
argument.
3. 1 Input/1 Output
Write a function with one input and one output. This function
should take an input argument(any data type) and retun the squared
value(s).
4. 2 Input/1 Output
Write a function with two inputs and one output. This function will
just take two variables, add them, and return the result.
5. 2 Input/2 Output
Write a function with two inputs and two outputs. This function
will take two matrices, and return the transpose of each.
No Input/No Output:
%Nothing is required except a clear screen and some spaces to display it at the properly visible location on the %screen.
1. function Display()
clc
disp(' HELLO HOW ARE YOU ')
end
2. 1 Input/No Output:
function Display(a)
clc
b = inputname(1);
disp('a')
end
3. 1 Input/1 Output:
function [y]=Display(x)
clc
disp(' The sqared Value of what you entered is ')
y=x^2;
end
4.2 Inputs /1 Output:
function [y]=Display(a)
clc
b = input('Give the value of b= ');
y=a+b;
disp(' sum of a and b is ')
end
5. 2 Inputs /2 Outputs:
function []=Display(a,b) % here you must call the fcn from
command prompt like this: Display([1 2],[3 4])
clc
y=a';
z=b';
disp(' transpose of a and b respectively are ')
disp(y);
disp(z);
end
% function will print the first output only at command prompt when called. that is the reason here i am using disp to %prind both variables
Get Answers For Free
Most questions answered within 1 hours.