Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
Mark Dillon
Mark Dillon il 31 Lug 2015
Risposto: Star Strider il 31 Lug 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

Risposte (1)

Star Strider
Star Strider il 31 Lug 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.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by