multiple function_handle in one function
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello there,
I have the following function handle (function of a cirlce):
f1=@(a)((x1-a(1)).^2+(y1-a(2)).^2-a(3).^2);
x=a(1);
y=a(2);
r=a(3);
x1 and y1 are generated randomly (10 points)
phi1 = linspace(0, 2*pi, 10);
r1 = -0.5 + (0.5 + 0.5) * rand(1,10);
x1 = sin(phi1) + 0.25 * r1;
y1 = cos(phi1) + 0.25 * r1;
To continue, I need the derivate of f1 for x, y and r in one function df(x0), where x0 describes inital values.
So, if i set for example x0=[0,0,1] i need df(x0) as a Matrix with the soultions of df out of x=0, y=0, r=1. I tried to build the derivates by hand:
DFx1= @(a) 2.*((sqrt((x1-a(1)).^2 + (y1-a(2)).^2) - a(3)).*(a(1)-x1))./(sqrt((x1-a(1)).^2 + (y1-a(2)).^2));
DFy1= @(a) 2.*((sqrt((x1-a(1)).^2 + (y1-a(2)).^2) - a(3)).*(a(2)-y1))./(sqrt((x1-a(1)).^2 + (y1-a(2)).^2));
DFr1= @(a) 2.*(a(3)-sqrt((x1-a(1)).^2 + (y1-a(2)).^2));
but I don't know how to continue.
Any ideas? Thanks
Sry for bad english, not my first language.
0 commentaires
Réponses (1)
Ameer Hamza
le 3 Déc 2020
Instead of defining three function handles, you can defined one vector-valued functions
df = @(a) [2.*((sqrt((x1-a(1)).^2 + (y1-a(2)).^2) - a(3)).*(a(1)-x1))./(sqrt((x1-a(1)).^2 + (y1-a(2)).^2));
2.*((sqrt((x1-a(1)).^2 + (y1-a(2)).^2) - a(3)).*(a(2)-y1))./(sqrt((x1-a(1)).^2 + (y1-a(2)).^2));
2.*(a(3)-sqrt((x1-a(1)).^2 + (y1-a(2)).^2))];
2 commentaires
Voir également
Catégories
En savoir plus sur Language Fundamentals dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!