Question

using matlab please present code for the following (ALL PARTS PLEASE AND THANK YOU) 1. No...

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.

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB...
Write a user defined MATLAB program that performs power factor correction. The inputs to the MATLAB function should be voltage across the load (in Vrms, assume 0 phase), frequency Resistance of the load Inductance of the load power factor of the load target power factor The output of the function should be the size of the capacitor that one would need to place in parallel with the load to reach the target power factor. Please submit the code for the...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that implements the bisection method. You function should take as input 4 arguments with the last argument being optional, i.e, if the user does not provide the accuracy tol use a default of 1.0e-6 (use varargin to attain this). Your function should output the approximate root, approx_root and the number of iterations it took to attain the root, num_its. However, if the user calls the...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar questions. Please post in a format that can be directly copied. Reasoning on answers would be most helpful but not required. Thank you in advance for your help. 2. Consider the following algorithm for finding the distance between the two closest elements in an array of numbers. ALGORITHM MinDistance(A[0..n − 1])//Input: Array A[0..n − 1] of numbers //Output: Minimum distance between two of its...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar...
Please post all code in Pseudo code. Please post ORIGINAL answers do not copy from similar questions. Please post in a format that can be directly copied. Reasoning on answers would be most helpful but not required. Thank you in advance for your help. 1.Design an algorithm to find all the common elements in two sorted lists of numbers. For example, for the lists 2, 5, 5, 5 and 2, 2, 3, 5, 5, 7, the output should be 2,...
1. Please write the following in C++ also please show all output code and comment on...
1. Please write the following in C++ also please show all output code and comment on code. 2. Also, use CPPUnitLite to write all test and show outputs for each test. Write CppUnitLite tests to verify correct behavior for all the exercises. The modifications are aimed at making the exercises more conducive to unit tests. Write a function that swaps (exchanges the values of two integers). Use int* as the argument type. Write a second swap function using a reference...
MATLAB ONLY: Find oldest house on the market? can't not use any built in function except...
MATLAB ONLY: Find oldest house on the market? can't not use any built in function except length and isnan to write this function if necessary . Inputs: dateConstruct - an array that will be linked to when each house was build dateRebuild - an array that will be linked to when eeach house was rebuild. However if an house has never been rebuild, the year will be Nan. Outputs: Numb - will serve as the index location for the oldest...
In the code space provided in Matlab Grader, create a function that: 1. Accepts an input...
In the code space provided in Matlab Grader, create a function that: 1. Accepts an input matrix A as its only input argument. Matrix A is a 3x3 matrix of random integers between 1 and 4 2. Produces and output matrix B as its only output argument. Matrix B will also be a 3x3 matrix. 3. Calculates the elements of matrix B such that: a. the values of B along the diagonal are equal to the respective elements in A...
Please provide commenting of code so I can understand how to solve this problem. Please provide...
Please provide commenting of code so I can understand how to solve this problem. Please provide text files. Using C++ Write a program that reads a given file, and then outputs the contents of it to another file. It should also print out the number of lines and the number of times each alphabetic character appears (regardless of case) in the input file at the end of the output file. It should prompt the user for the input and output...
Create a MATLAB Function for the half pipe volume problem. inputs length and OD outputs the...
Create a MATLAB Function for the half pipe volume problem. inputs length and OD outputs the volume in gals %half_pipe.m %calculates the volume of the cylinder and converts volume to gallons. %Variables %len=length %od=outer diameter len=input('Enter length of cylinder: '); od=input('Enter outer diameter of cylinder: '); %Calculate id=0.8*od; vol_outer=0.5*pi*(od/2)^2*len; vol_inner=0.5*pi*(id/2)^2*len; %Result vol=vol_outer-vol_inner; v_gals=vol/231; %Output fprintf('The volume of gallons is %1.4f gal \n ',v_gals) Call the function from the command window to run. Example for command window: >>halfpipe_vol = halfpipe_volume_function(10,4) [return...
Please do this in Matlab Using a single for-loop and no if-statements, write a code that...
Please do this in Matlab Using a single for-loop and no if-statements, write a code that will create a 10x10 matrix with 2 on the diagonal, and -1 on any entry right next to the diagonal.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT