How do I turn this function into a 2-D operation?

3 ビュー (過去 30 日間)
Mark Dillon
Mark Dillon 2015 年 7 月 31 日
回答済み: Star Strider 2015 年 7 月 31 日
I have this function file:
if true
% function [newx,newv,F]=Leaf(x,v,m,h)
% Inputs are x (meters),
% v (meters/second),
% m (kg)
% Outputs are newx (meters)
% newv (meters/second),
% F (Newtons)
% Equations
F = 0.2.*sin(x).*(x.^2+x);
a = F./m;
newx = x+h.*v;
newv = v+h.*a;
end
end
I need to know make it into a two dimensional operator with the functions:
* r(x,y) = sqrt((x.^2)+(y.^2));
* theta(x,y) = atan(y./x);
* Fx(x,y) = -0.01 sin(theta(x,y))-0.01.*r(x,y).*x
* Fy(x,y) = -0.01 cos(theta(x,y))-0.01.*r(x,y).*y
* x(n+1) = x(n) + h*v
* v(n+1) = v(n) + h*a
* a = F/m
I am not really sure how 2-D vectors set up in these functions. Thank you

回答 (1 件)

Star Strider
Star Strider 2015 年 7 月 31 日
You can make any of them into anonymous functions. For instance:
Fx = @(x,y) -0.01 sin(atan2(y,x))-0.01.*hypot(x,y).*x;
I did some substitutions to take advantage of built-in functions that would at least be a bit more efficient and faster, and probably more precise.

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by