Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Mark Dillon
Mark Dillon am 31 Jul. 2015
Beantwortet: Star Strider am 31 Jul. 2015
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

Antworten (1)

Star Strider
Star Strider am 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.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by