multiple function_handle in one function

3 views (last 30 days)
Nico Lange
Nico Lange on 3 Dec 2020
Commented: Ameer Hamza on 3 Dec 2020
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.

Answers (1)

Ameer Hamza
Ameer Hamza on 3 Dec 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))];

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!