multiple function_handle in one function
이전 댓글 표시
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.
답변 (1개)
Ameer Hamza
2020년 12월 3일
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))];
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!