How to write a function that utilizes unit vectors?

4 ビュー (過去 30 日間)
Maria Gnucheva
Maria Gnucheva 2021 年 5 月 2 日
回答済み: Benjamin Großmann 2021 年 5 月 3 日
I want to implement the following vector function in Matlab:
This function utilizes unit vectors, denoted here by , and . I know how to implement the functions for the different directions, but I don't know how to combine them into a single function that retains all vectorial components. Any help would be appreciated.

採用された回答

Benjamin Großmann
Benjamin Großmann 2021 年 5 月 3 日
If you can calculate the vector components (i.e. directions) than you only have to arrange them into an array. Suppose that you have calculations for the single directions in functions f1, f2 and f3:
function F = vectorFunction(r, theta, phi)
% calculate the directions
F1 = f1(r, theta, phi);
F2 = f2(r, theta, phi);
F3 = f3(r, theta, phi);
% arrange directions in array (here: column vector)
F = [F1; F2; F3];
end
function out = f1(r, theta, phi)
out = r + theta + phi;
end
function out = f2(r, theta, phi)
out = r * theta * phi;
end
function out = f3(r, theta, phi)
out = r * theta - phi;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by