Write a MATLAB function named mag_force Inputs: (No input validation is required) 1. a scalar value representing charge 2. a 1x3 vector representing velocity 3. a 1x3 vector representing a magnetic field. 4. a 1x3 unit vector representing an axis. Output: 1. a scalar value calculated by taking the the charge times the cross product of velocity and magnetic field and then taking the dot product of that result with the unit vector of the axis F=q(v x B) Force = F . u Example: clc; format compact; e e]) mag_force (6, [1 2 3],[-2 0 1],[1 Should display this in the command window ans = 12 Your code should work for any set of inputs. Do not include test cases, clear all, etc as part of your submission.

Respuesta :

Answer:

The implementation was done with 5 lines of codes given below

Explanation:

mag_force(6, [1 2 3], [-2 0 1], [1 0 0])

function Force = mag_force(q, v, B, u)

F = q .* cross(v, B);

Force = dot(F, u);

end %This brings an end to the program

% This display ans = 12 on the MATLAB command window

% indicating a right implementation