finding magnitude of a vector (2024)

19vues (au cours des 30derniers jours)

Afficher commentaires plus anciens

Ashlianne Sharma le 7 Nov 2020

  • Lien

    Utiliser le lien direct vers cette question

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector

  • Lien

    Utiliser le lien direct vers cette question

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector

Commenté: Ashlianne Sharma le 8 Nov 2020

Ouvrir dans MATLAB Online

Hi all, I am trying to make a function and the first step within my function is to find the magnitude of a vector that I have named on another script. How do I do this? I willo put my code below to explain more.

FROM FUNCTION PAGE

function[a, e, nu, i, O, m] = hw_COE_sharmaAshlianne(R, V)

% Inputs

% R = Radius vector [km]

% V = Velocity vector [km/s]

%

% Outputs

% a = semi major axis [km]

% e = eccentricity [no units]

% nu = true anomoly [degrees]

% i = inclination [degrees]

% O = right ascention of the ascending node(RAAN) [degrees]

% w = argument of perigee [degrees]

% Known values

m = 398600; % [km^3/s^2]

% Step one find the magnitude of the radius and velocity vectors

r = norm(R);

v = norm(V);

FROM SCRIPT

% Create a structure for our function to find COE parameters

Rvector = [15370 1400 21950]; % [km]

Vvector = [-0.1 3.84 -0.2]; % [km/s]

% Call function with the structured variables we created above

[a, e, nu, i, O, m] = hw_COE_sharmaAshlianne(Rvector, Vvector);

so to reiterate my question, how do I find the magnitude of Rvector that is defined in my script on my function page (STEP ONE IN FUNCTION)

16commentaires

Afficher 14 commentaires plus anciensMasquer 14 commentaires plus anciens

VBBV le 7 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117465

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117465

Modifié(e): Walter Roberson le 8 Nov 2020

Ouvrir dans MATLAB Online

>> hw_COE_sharmaAshlianne([...],[...])

Go to the command window and enter the vectors as shown above. Alternately run the script file in which the you are calling the function hw_COE_sharmaAshlianne(Rvector,Vvector)

Ashlianne Sharma le 7 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117525

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117525

Ouvrir dans MATLAB Online

I have done that, I made the separate script by which I call my function with

[a, e, nu, i, RAAN, w] = hw_COE_sharmaAshlianne(Rvector, Vvector);

just as I stated in my original question.

Again, the question I asked is how do I code to find the magnitude of the vector because as I put above, it does not work. I would appreciate if you help me with the question I asked??

r = norm(R);

v = norm(V);

I tried putting the lines

r = Rvector;

but that does not work.

VBBV le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117585

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117585

Modifié(e): Walter Roberson le 8 Nov 2020

Ouvrir dans MATLAB Online

Since norm calculates the magnitude of the vector and is defined inside the function as

function[a,e,nu,i,O,m]=

w_COE_sharmaAshlianne(Rvector,Vvector)

...

r = norm(Rvector);

v = norm(Vvector)

...

end % close function file with end statement

Close function file with end

Ashlianne Sharma le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117675

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117675

Okay that makes a lot of sense! I am still running into an issue here at these lines of code. The error message I am getting it that I don't have enough input arguments (regarding my Rvector and Vvector).

In order for me to define the Rvector and the Vvector on my script, how do I get those values onto my function page?

I don't know if I am making sense haha, I guess what I am trying to say is how do I call a function with specific values that will run through my function page if I dont explicitely define the R and V vectors on my function page?

VBBV le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117700

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117700

Modifié(e): VBBV le 8 Nov 2020

In function page just define the same variable vectors as defined in script file as shown in my message. Inside the function you don't require or have to define R and V again. Instead you pass the vectors Rvector and Vvector as arguments and use them with norm

VBBV le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117710

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117710

If you delete the semicolon at the

norm(Rvector) norm(Vvector)

You can see the values of magnitude in command window once the run is completed .

Ashlianne Sharma le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117725

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117725

Okay, so you had an amzing explaination for the norm aspect, thank you so much.

This question seems simple, But I struggle with this since the start of the class.

Script %note I changed Rvector to R for simplicity

% Define given vectors as variables

R = [15370 100 21950]; % [km]

V = [-0.1 3.84 -0.2]; % [km/s]

% Call function with the structured variables we created above

[a, e, nu, i, RAAN, w] = hw_COE_sharmaAshlianne(R, V);

Function: line one, after this line, I finished the rest of my code.

function[a, e, nu, i, RAAN, w] = hw_COE_sharmaAshlianne(R, V)

Question:

When I was getting your help, I just defined my vectors inside my function. Like you say above, you dont need to do this. I took out my defined vectors from my function and I now get an error message saying I do not have enough input arguments. I don't know how to pass the variables through. Like I know the variables have to be the same on the script and function page, But that isnt working for me. Any explaination on passing variables through the function would be great help... The matlab version online hasnt been too much of help. Thank you Vasishta!

VBBV le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117745

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117745

Did you name the file exactly the same as function name? I.e. the name of the file which contains your function code and name of the function must be same. The name of file in which function code is present must be

hw_COE_sharmaAshlianne.

If you name something else then it will not run.

Ashlianne Sharma le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117750

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117750

yeah I saved the file as the same name as my function. Everything was working until I removed the R and V vectors from the function file

Ashlianne Sharma le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117755

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117755

So when I run my script that I call my function on, it works perfectly, however, I when I run my function file, i get the message that there are not enough input arguments

VBBV le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117760

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117760

Oh. You seem to have changed the names of variables Rvector and Vvector in your script file from which you're calling function. Change it to

Rvector = [values] Vvector = [values]

VBBV le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117770

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117770

Modifié(e): VBBV le 8 Nov 2020

Ouvrir dans MATLAB Online

Keep the same structure like before in the first post.

% if true

% code

% end

Rvector = [15370 1400 21950]; % [km]

Vvector = [-0.1 3.84 -0.2]; % [km/s]

%

[a, e, nu, i, O, m] = hw_COE_sharmaAshlianne(Rvector, Vvector);

VBBV le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117775

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117775

Rvector, Vvector must have same names in script file and function file

Ashlianne Sharma le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117790

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117790

okay, that makes sense. Just so I am understanding,

script

Rvector = [15370 1400 21950]; % [km]

Vvector = [-0.1 3.84 -0.2]; % [km/s]

%

[a, e, nu, i, O, m] = hw_COE_sharmaAshlianne(Rvector, Vvector);

Function

function[a, e, nu, i, RAAN, w] = hw_COE_sharmaAshlianne(Rvector, Vvector)

and everywhere in my code that R and V exist in my function, the variable should be Rvector and Vvector aswell?

VBBV le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117800

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117800

Modifié(e): VBBV le 8 Nov 2020

Ouvrir dans MATLAB Online

https://in.mathworks.com/help/matlab/ref/function.html

Check the syntax of function declaration. You require space between the word function and output variable vector

%if true

% code

%end

function [a,e,nu,i,O,m]=

w_COE_sharmaAshlianne(Rvector,Vvector)

...

r = norm(Rvector);

v = norm(Vvector)

...

end % close function file with end statement

Ashlianne Sharma le 8 Nov 2020

Utiliser le lien direct vers ce commentaire

https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117815

  • Lien

    Utiliser le lien direct vers ce commentaire

    https://fr.mathworks.com/matlabcentral/answers/639990-finding-magnitude-of-a-vector#comment_1117815

Okay, Thank you so much for your help!! i will definitely look more to the page you sent me, I think that may be very useful. Again, Thank you so much for taking So SO much time out to help me. I am just a struggling college student haha but yes, I really appreciate your time and help Vasishta!

Connectez-vous pour commenter.

Connectez-vous pour répondre à cette question.

Réponses (0)

Connectez-vous pour répondre à cette question.

Voir également

Catégories

MATLABLanguage FundamentalsMatrices and ArraysMatrix Indexing

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

  • magnitude of vector
  • norm(r)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Une erreur s'est produite

Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.


Translated by finding magnitude of a vector (18)

finding magnitude of a vector (19)

Sélectionner un site web

Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .

Vous pouvez également sélectionner un site web dans la liste suivante :

Amériques

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asie-Pacifique

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contactez votre bureau local

finding magnitude of a vector (2024)
Top Articles
Fantasy Basketball Sleepers: Jonathan Isaac, Paul George, Jalen Green, Paul Reed
Sixers Eastern Conference preview: Will the Mikal Bridges trade make the Knicks a championship-caliber team?
Roblox Roguelike
Le Blanc Los Cabos - Los Cabos – Le Blanc Spa Resort Adults-Only All Inclusive
FFXIV Immortal Flames Hunting Log Guide
Body Rubs Austin Texas
Falgout Funeral Home Obituaries Houma
Bluegabe Girlfriend
Farmers Branch Isd Calendar
J Prince Steps Over Takeoff
อพาร์ทเมนต์ 2 ห้องนอนในเกาะโคเปนเฮเกน
The Banshees Of Inisherin Showtimes Near Regal Thornton Place
Available Training - Acadis® Portal
boohoo group plc Stock (BOO) - Quote London S.E.- MarketScreener
Rachel Griffin Bikini
Nail Salon Goodman Plaza
Pekin Soccer Tournament
Moving Sales Craigslist
Bekijk ons gevarieerde aanbod occasions in Oss.
Mc Donald's Bruck - Fast-Food-Restaurant
Little Rock Skipthegames
Jayah And Kimora Phone Number
Elbert County Swap Shop
Piri Leaked
Powerschool Mcvsd
Mynahealthcare Login
Gunsmoke Tv Series Wiki
Yu-Gi-Oh Card Database
Sinfuldeed Leaked
Best Laundry Mat Near Me
Kleinerer: in Sinntal | markt.de
Clearvue Eye Care Nyc
Nacogdoches, Texas: Step Back in Time in Texas' Oldest Town
Att U Verse Outage Map
Leland Nc Craigslist
Solve 100000div3= | Microsoft Math Solver
2008 Chevrolet Corvette for sale - Houston, TX - craigslist
Leatherwall Ll Classifieds
Gold Nugget at the Golden Nugget
How much does Painttool SAI costs?
How to Print Tables in R with Examples Using table()
Avance Primary Care Morrisville
Workday Latech Edu
Erespassrider Ual
Clock Batteries Perhaps Crossword Clue
Guy Ritchie's The Covenant Showtimes Near Look Cinemas Redlands
Makes A Successful Catch Maybe Crossword Clue
Sleep Outfitters Springhurst
Free Carnival-themed Google Slides & PowerPoint templates
Grace Charis Shagmag
Jovan Pulitzer Telegram
Secondary Math 2 Module 3 Answers
Latest Posts
Article information

Author: Msgr. Refugio Daniel

Last Updated:

Views: 6395

Rating: 4.3 / 5 (54 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Msgr. Refugio Daniel

Birthday: 1999-09-15

Address: 8416 Beatty Center, Derekfort, VA 72092-0500

Phone: +6838967160603

Job: Mining Executive

Hobby: Woodworking, Knitting, Fishing, Coffee roasting, Kayaking, Horseback riding, Kite flying

Introduction: My name is Msgr. Refugio Daniel, I am a fine, precious, encouraging, calm, glamorous, vivacious, friendly person who loves writing and wants to share my knowledge and understanding with you.