How do I turn this function into a 2-D operation?
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Star Strider
on 31 Jul 2015
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 Comments
See Also
Categories
Find more on Array Geometries and Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!