Solution:
1.a number is divisible by 2 or not
%%---------- Code Starts here-------------%%
prompt = 'What is the original value? ';
x = input(prompt);
if rem(x,2)==0
disp('divisible by 2')
else
disp('not divisible by 2')
end
%%------------------- END
---------------------%%
2.average of vector elements
(a) x=[1 2 3 4];
%%--------- Code start here -----------%%
x=[1 2 3 4];
add=0;
for i=1:4
add=add+x(i);
end
average =add/4
%%------------------ END --------------------%%
(b)x=[1 2 3 4 5 6];
%%------------ Code starts here ----------------%%
x=[1 2 3 4 5 6];
add=0;
for i=1:4
add=add+x(i);
end
average =add/6
%%------------------- END ------------------------%%
Use Matlab Q1. Write a code to determine if a number is divisible by 2 Q2....
Using MatLab Write a function called PrimeFinder that receives an integer n as an input argument, and provides an output argument called Primes that is a vector containing all prime numbers between 2 and n, inclusive. Verify the correctness of your code with inserting 13 as the input argument, and check that your output is Primes = [2,3,5,7,11,13]. You are NOT allowed to use any directly relevant MATLAB built-in function such as divisors, etc. NOTE: A prime number is a...
NOTE: WRITE MATLAB CODE then the results for each QUESTIONS: Q1: For the system of the equations [2x; + 3xy + x3 = 9 x2 + 2x2 + 3x3 = 0 3x; +x2+2x3 = 8) compute the unknowns Xı, X2, and X3 using the inverse matris method. Q2: Simplify the complex number z and express it both in rectangular and polar form. (3+ j4)(5 + j2)(2 260°) (3+j6)(1+12) NOTE: WRITE MATLAB CODE then the results for each QUESTIONS: Q3: Suppose...
Matlab code for this problem.
1[35pl Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two points (A and B) in space. For the func- tion name and arguments, use n = unitvec (A,B). The input to the function are two vectors A and B, each with the Cartesian coordinates of the corre- sponding point. The output is a vector with the components of the unit vector in the direction from...
Repeat SPIDER 2 Q1, but write a function that accepts a year as an input argument and determines whether that year is a leap year. The output should be the variable extra_day, which should be 1 if the year is a leap year and 0 otherwise. Spider two Q1 1. Write code to determine whether a year is a leap year. Use the mod function. The rules for determining leap years in the Gregorian calendar are as follows: 1. All...
please solve in matlab
1[35p) Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two points (A and B) in space. For the func- tion name and arguments, use n = unitvec (A,B). The input to the function are two vectors A and B, each with the Cartesian coordinates of the corre- sponding point. The output is a vector with the components of the unit vector Join the direction from A...
Matlab code
4) Write a function leadzero(v) which takes as input a vector v and as output, c, returns the number of zeros at the beginning of v (number of zero elements before any non-zero element). For example, for input (-5, 5, 11] the output would be 0. If the input is [0, 0, 3, 0, 0, 0], the output would be 2. If the input is [0, 0, 0, 0, 7, 4) the output would be 4. 5) Write...
q2 please
find x1.x2.x3.x4 using matlab
&73 3:45 zain JO 4ll ring Q1 a function with the name "Area Circumference" to calculate the area and circumference tput) of a rectangle. Define the inputs of this function as required. (6marks) rite a manuscript to solve the following system of equations based on [A][x] =[b)]. Find x1, x2, . (5 Marks) 2x1+ x2-3 +2x4 4 x1+5x2-3ax3 +604 -2x1 +5a2-2r3 +6x4= 4 4x1+11x2-4x3+8x4 = 5 Q3: Having f(x) = 3x6-13x2 + 2x, Integratef...
*MATLAB CODE* 3)Write a function 'mydsort' that sorts a vector in descending order (using a loop, not the built-in sort function). 4)write a function that will receive a vector and will return two index vectors: one for ascending order and one for descending order. Check the function by writing a script that will call the function and then use the index vectors to print the original vector in ascending and descending order. **Please make sure they work. I have found...
please solve then upload matlab code
Thanks
1. The function f(z, y) (a-x)2 + b(y-12)2 is called Rosenbrock's banana function. It is often used as a benchmarking test for optimization algorithms becatse it is easy to find the minimum by hand but often very difficult to find numerically. Throughout the problem, we will use the values a = 2 and b 10. You can plot this function using the following code: x3:0.1:3; y = -10:0.2:10; Cx,Ymeshgrid(x,y); Z(2-X).2 10* (Y-X. 2)....
17. Prime Numbers A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and S. The number 6, how- ever, is not prime because it can be divided evenly by 1, 2, 3, and 6. Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or...