Question

1[35p) Write a user-defined MATLAB function that determines the unit vector in the direction of the line that connects two po

please solve in matlab

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • Suppose, x_0i + y_0j + k_0k is A vector and x_1i + y_1j + k_1k is B vector, then the unit vector connecting A and B is given by

\frac{(x_1-x_0)i + (y_1-y_0)j +( k_1-k_0)k}{\sqrt{(x_1-x_0)^2 + (y_1-y_0)^2 +( k_1-k_0)^2}}

Matlab function:

function n = unitvec(A, B)

n = B-A;

n = n./(sqrt(sum(n.^2)));

end

a.) output for 2D points

b.) output for 3D points

Add a comment
Know the answer?
Add Answer to:
please solve in matlab 1[35p) Write a user-defined MATLAB function that determines the unit vector in...
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
  • Matlab code for this problem. 1[35pl Write a user-defined MATLAB function that determines the unit vector...

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

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

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

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

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

  • [(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 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...

  • In Matlab Write a function dubinsLSR.m that computes a two-dimensional left-straightright (LSR) Dubins path solution. Your...

    In Matlab Write a function dubinsLSR.m that computes a two-dimensional left-straightright (LSR) Dubins path solution. Your function should take the following input arguments (in this order): W0, W3, R. Your function should return Dubins waypoints W1, W2. R is turning radius, and each waypoint Wi must be a Matlab three-element row vector of Cartesian coordinates (xi , yi , ψi). All distance values are specified in meters, and headings ψi are in radians. In the LSR Dubins solution, the aircraft...

  • Using MATLAB Please Write a MATLAB function that takes coord natos of four points as inputs and returns the coord nates of ntersection of the line passing through ooints 1 and 2 and the line passing t...

    Using MATLAB Please Write a MATLAB function that takes coord natos of four points as inputs and returns the coord nates of ntersection of the line passing through ooints 1 and 2 and the line passing through points 3 and 4. For function name and inout arguments, use: P line_int(P1, P2, P3, P4) The function should be able to handle row or column vector entries. This function will use a sub-function called line_eq. This sub-function takes coordinates of two points...

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
ADVERTISEMENT