How do I turn this function into a 2-D operation?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Array Geometries and Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!