이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Surf a function with different values
조회 수: 2 (최근 30일)
이전 댓글 표시
I'm trying to surf a function f that takes 2 values: 1 if (x,y) is in A and 2 if (x,y) is in B. How can I do that? I attach also a drawing for x,y.

채택된 답변
Torsten
2023년 5월 21일
Define the function as
f = @(x,y) (y>=2*x) + 2*(y<2*x);
and make a surface plot.
댓글 수: 17
Alexandra Roxana
2023년 5월 21일
편집: Alexandra Roxana
2023년 5월 21일
But the function doesn't depend on x and y. It is a constant function. And I want to go further with more triangles dividing the domain. And to make it have a different value within each triangle.
Torsten
2023년 5월 21일
편집: Torsten
2023년 5월 21일
The function has exactly the values you want:
f = @(x,y) (y>=2*x) + 2*(y<2*x);
f(0,1)
ans = 1
f(1,0)
ans = 2
But I admit: Defining a function with prescribed values on each triangle of a triangulation will soon become a hard job. And I really don't understand what it should be good for ...
Alexandra Roxana
2023년 5월 21일
I've been thinking of this problem for weeks and can't seem to come to some results.
Alexandra Roxana
2023년 5월 21일
편집: Alexandra Roxana
2023년 5월 21일
Long story short: I want to calculate the pressure on each triangle from the red domain. The left-hand side of the formula is the pressure on each triangle; the right-hand side is the sum of values of each node from the triangle. The thing is the pressure is constant on each triangle and it has to look like that in the surf. Before it looked like a continuous function which isn't right. And I wanted at first to begin with a simple example.

Torsten
2023년 5월 21일
f = @(x,y) (y>=2*x) + 2*(y<2*x);
x = linspace(0,1,100);
y = linspace(0,2,100);
[X,Y] = ndgrid(x,y);
surf(X,Y,f(X,Y))
shading interp
colorbar

Alexandra Roxana
2023년 5월 22일
It looks really good but there's a slight problem: what can I modify so I can see only the two triangles in the figure? It must look like a jump from 1 to 2.
Torsten
2023년 5월 22일
Or:
f = @(x,y) (y>=2*x) + 2*(y<2*x);
x = linspace(0,1,100);
y = linspace(0,2,100);
[X,Y] = ndgrid(x,y);
contourf(X,Y,f(X,Y))
colorbar

Alexandra Roxana
2023년 5월 22일
No, it has to look like the first one without the middle part, in 3D also.
Alexandra Roxana
2023년 5월 22일
Probably the function has to be modified, I momentarily don't see how.
Torsten
2023년 5월 22일
You might want to play with this representation:
x1 = [0,0,1];
y1 = [0,2,2];
z1 = [1,1,1];
x2 = [0,1,1];
y2 = [0,0,2];
z2 = [2,2,2];
hold on
s1 = fill3(x1,y1,z1,'r');
s2 = fill3(x2,y2,z2,'b');
hold off
view(25,45)
zlim ([0 3])
rotate(s1,[0 0 1],180)
rotate(s2,[0 0 1],180)

Alexandra Roxana
2023년 5월 23일
편집: Alexandra Roxana
2023년 5월 23일
Unfortunately that's not going to help me very much because I want to go further and do the same thing but with more triangles like in this case and in each triangle the function to have a different value:

Torsten
2023년 5월 23일
Alexandra Roxana
2023년 5월 27일
The method from the link seems to work; however I'm a bit confused with the values of n1, n2 and n3. I don't know what values I should put: if I put [1,1,1] the first coordinates are different, the rest is the same as should be. So I'm guessing the choice of n1, n2 and n3 is wrong.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)

