필터 지우기
필터 지우기

multiple function_handle in one function

조회 수: 3 (최근 30일)
Nico Lange
Nico Lange 2020년 12월 3일
댓글: Ameer Hamza 2020년 12월 3일
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
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))];
  댓글 수: 2
Nico Lange
Nico Lange 2020년 12월 3일
Thank you :)
Ameer Hamza
Ameer Hamza 2020년 12월 3일
I am glad to be of help!!! :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by