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...
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...
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...
using MATLAB Write a function which will take two inputs: an array ? and an integer...
using MATLAB Write a function which will take two inputs: an array ? and an integer ?. Here, 1 <= ? < ?????h(?). The objective is to find a contiguous subarray of length ? with the largest sum, within the array ?. The output of the function will be that largest sum. For example, x = [1 2 -1 3], and k =2. Then there are 3 possible contiguous subarrays. 1st subarray : [ 1 2], sum = 3 2nd...
USING MATLAB Write a MATLAB function that simulates a single roll of a n-sided die. The...
USING MATLAB Write a MATLAB function that simulates a single roll of a n-sided die. The inputsand outputs of the function are: Inputs: •The probabilities for each side, given as a vector p = [p1,p2...pn] Outputs: •The number onthe face of the die after a single roll, i.e.onenumber fromthe setof integers {1, 2 ,....n} Note: The sum p1+p2+.....pn must be equal to 1.0, otherwise the probability values are incorrect. Savethe function as: nsided_die(p) Test the functionwitha 5-sided die,where the probabilities...
Please code using C# Complete the two methods, highest() and lowest(). Both methods are static with...
Please code using C# Complete the two methods, highest() and lowest(). Both methods are static with a double return type and one integer parameter. Both methods will accept user input of as many numbers as the integer parameter’s value. The highest() method will return the largest number input. The lowest() method will return the smallest number input. Examples: The call highest(3) with user inputs of [5, 60, 2] will return the value of 60 The call lowest(3) with user inputs...
USING MATLAB Write a program called QuadProg that determines the roots of a quadratic equation. Use...
USING MATLAB Write a program called QuadProg that determines the roots of a quadratic equation. Use functions to implement each action. Zip you directory of *.m files into a single file and turn this in on BBLearn under Class Activities. QuadProg write a function called getInputs to get a single input value. write a function called findDiscriminant write a function called findDenominator write a function called findRoot which will be used for both roots write a function called displayResults displayResults...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT