Filter löschen
Filter löschen

multiple function_handle in one function

3 Ansichten (letzte 30 Tage)
Nico Lange
Nico Lange am 3 Dez. 2020
Kommentiert: Ameer Hamza am 3 Dez. 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.

Antworten (1)

Ameer Hamza
Ameer Hamza am 3 Dez. 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 Kommentare
Nico Lange
Nico Lange am 3 Dez. 2020
Thank you :)
Ameer Hamza
Ameer Hamza am 3 Dez. 2020
I am glad to be of help!!! :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Language Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by