필터 지우기
필터 지우기

Define a family of functions

조회 수: 4 (최근 30일)
Quang Huy Pham
Quang Huy Pham 2023년 2월 4일
편집: John D'Errico 2023년 2월 4일
I want to define a family of functions f(r) := @(x,y) x^2+y^2-r^2 for each r>0.
I can define a sequence of functions f(1), ..., f(n) by creating a cell array of size n*1
f = cell{n}
for k=1:n
f{k} = @(x,y) x.^2+y.^2-n^2
end
However, it is not possible to create an infinite cell array indexed by the set of positive real numbers. I would like to know an alternative way to define family of functions.

채택된 답변

John D'Errico
John D'Errico 2023년 2월 4일
편집: John D'Errico 2023년 2월 4일
DON'T DO IT THAT WAY. Instead, define ONE function. One function to rule them all. (Sorry. That last part just slipped out.)
Seriously. Define one function.
circfamily = @(x,y,r) x.^2 + y.^2 - r.^2;
Any single function in that family is now accessible simply as:
r = 5;
circ_5 = @(x,y) circfamily(x,y,r);
Or you might just do
circ_5 = @(x,y) circfamily(x,y,5);
In any case, we can now use that member of the family.
fimplicit(circ_5)
axis equal
We can even plot the entire family of such functions as a conic surface.
fimplicit3(circfamily,[-5,5,-5,5,0,5])
xlabel X
ylabel Y
zlabel R
grid on
box on
axis equal
There is no need to define the entire set of members of that family in advance. Anyway, you CANNOT explicitly define infinitely many functions, even if you wanted to do so. But essentially circfamily does exactly that implicitly, yielding infinitely many functions.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2023년 2월 4일
If you could define a "family of functions" in MATLAB, what properties would you want such a thing to have? If there were class familyOfFunctions then what methods would you want the class to have?
For example if you define that particular family of functions without providing a specific value for r, then do you need to be able to integral2() the family over specific bounds and get out a family of solutions that you could then instantiate for a particular r to get back the corresponding numeric integral?... and if so then would it be acceptable to layer this all on top of the Symbolic Toolbox, or does it need to operate without the Symbolic Toolbox?
  댓글 수: 1
Quang Huy Pham
Quang Huy Pham 2023년 2월 4일
Thanks for your answer. Yes, I want to integral2 these functions over some domains for random values of r. If I could define a family of functions f(r), I don't need to define a new function f inside the loop and directly use integral2(f{r},-1,1,-1,1). But now I realize that it doesn't matter whether f is defined inside or outside the for loop.
for j = 1:5
r = rand;
f = @(x,y) x.^2+y.^2-r^2;
integral2(f,-1,1,-1,1);
end

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

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by