Question

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 po

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Function file: (unitvec.m)

function n=unitvec(A,B)
% direction of the vector
n=B-A;
% unit vector in the direction
n=n/(sqrt(sum(n.*n)));
end

Screenshot:

1 2 3 function n=unitvec(A,B) direction of the vector n=B-A; unit vector in the direction n=n/ (sqrt (sum(n.*n))); end 4 5 6

Save the above program as unitvec.m in the working directory.

Question (a):

Script file:

clear
clc
A=[1.2 3.5];
B=[12,15];
n=unitvec(A,B)

Screenshot:

1 N 3 clear clc A=(1.2 3.5]; B=(12,15]; n=unitvec(A,B) 4 5

Save the above program in the working directory and execute it.

Result:

n = 0.6846 0.7289 fx >>

Question (b):

Script file:

clear
clc
A=[-10,-4,2.5];
B=[-13,6,-5];
n=unitvec(A,B)

Screenshot:

1 2 نما clear clc A=[-10,-4,2.5]; B=[-13,6,-5); n=unitvec (A,B) 4 5 -

Save the above program in the working directory and execute it.

Result:

n = -0.2334 0.7779 -0.5834 fx >

I hope this will help you, please give me thumbs up.

Add a comment
Know the answer?
Add Answer to:
Matlab code for this problem. 1[35pl Write a user-defined MATLAB function that determines the unit vector...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please solve in matlab 1[35p) Write a user-defined MATLAB function that determines the unit vector in...

    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...

  • B.1 Write a MATLAB user-defined function for interpolation with linear splines Name the function Yint =...

    B.1 Write a MATLAB user-defined function for interpolation with linear splines Name the function Yint = Linear Splines, y, rint), where the input ar- guments and y are vectors with the coordinates of the data points and rint is the coordinate of the interpolated point. The output argument Yint is the y value of the interpolated point. Also write a program in a script file that plots the data points and the curve of the Linear splines that interpolates the...

  • 1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector...

    1) a) Write MATLAB function that accepts a positive integer parameter n and returns a vector containing the values of the integral (A) for n= 1,2,3,..., n. The function must use the relation (B) and the value of y(1). Your function must preallocate the array that it returns. Use for loop when writing your code. b) Write MATLAB script that uses your function to calculate the values of the integral (A) using the recurrence relation (B), y(n) for n=1,2,... 19...

  • 1. in Matlab, write a user-defined function, with two input (r,theta) , θ expressed in degrees)...

    1. in Matlab, write a user-defined function, with two input (r,theta) , θ expressed in degrees) and two output arguments (X,Y). The inputs are a location on a polar coordinates corresponding to Cartesian plane expressed in rectangular coordinates. The picture below describes the problem. X, Y rcos θ Some formula that you may need: x = r * cos (theta * pi/180); y r * sin(theta * pi/180); Test your code for r=7, theta=55° and present your results.

  • get the system shown in Fig. 1. vector product gives 1 j = ucts of unit...

    get the system shown in Fig. 1. vector product gives 1 j = ucts of unit vectors i, j, andA So there are two kinds of coor tor products of unit vectors. is called a right-handed sys systems, and we'll follow th EXAMPLE 1.11 CALCULATING A VECTOR PRODUCT Vector A has magnitude 6 units and is in the direction of the +x-axis. Vector B has magnitude 4 units and lies in the xy-plane, making an angle of 30° with the...

  • *MATLAB CODE* 3)Write a function 'mydsort' that sorts a vector in descending order (using a loop,...

    *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...

  • MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the...

    MATLAB Problem HW7P2 (20 points) (5 pts) Write a user-defined MATLAB function called HW7P2_fn for the following math function 3 o-0.47x The input to the function is x and the output is y. Write the function such that x can be an array (use element-by-element operations) (15 pts) Use the function in (a) the command window to calculate y(-2) and y(5) (b) a script file HW7P2.m to determine y(x) for 0.001 Sx S 10 with 1000 points. Hint: Use the...

  • [(b) 3 points, classifypoints.m) Implement the Matlab function function category - classifypoints...

    Implement the following matlab function to classify points. [(b) 3 points, classifypoints.m) Implement the Matlab function function category - classifypoints(file, points) %Reads parameters from file and classifies points into two %categories, A or B. This file is created by netbp %points is a matrix with two rows, where point(: , i) contains the /(x,y) coordinates of point i %Returns vector category, where category (i) is 1, A, if %points (1 , i) > points (2 , i) and 0 ,...

  • matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name...

    matlab 1. Write a MATLAB user-defined function that finds the largest element(s) of a matrix. Name the function [max_value, max_index] - LASTNAMES matrix max (x), where input argument x is a vector or matrix (not a scalar), and the outputs are the maximum value(s) and indexes of the maximum value(s) of the mput x. Do not use MATLAB functions max() or find(). Use loops and if branches to determine the maximum elements of matrix. Check for correct number and valid...

  • Please use MatLab and comment code. Problem 2 Write a MATI AB user-defined function y-M?SotxType): x...

    Please use MatLab and comment code. Problem 2 Write a MATI AB user-defined function y-M?SotxType): x is a vector containing numbers. and Type can be 'Ascending' or Descending'. This function should sort the given vector x in the ascending or descending order based on the user's request and return the desired vector as the output. Do not use MATLAB built-in function sort. Hint: When you call this function you need to use for Ascending or Descending since they are strings.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT