Plotting Level Curves after function

how do i plot level curves in matlab
such as c = 0, 0.5, 1, ..., 3.
i have already computed the code for the function
f (x, y) = (x2 + 3y2)e1x2 y2
over the domain 1 x 1, 1 y 1.

답변 (1개)

Star Strider
Star Strider 2023년 3월 24일

0 개 추천

Use the contour function.
You can use fcontour, however it will not be possible to export its results to plot with contour.

댓글 수: 5

Torsten
Torsten 2023년 3월 24일
"fimplicit" might also be an option.
@Torsten — I considered that, however that could require at least one explicit loop, where contour could do all the ‘c’ values using the LevelList argument. I would have simulated it here, except that I have no idea whether ‘e’ is a variable or the exponential function exp.
Assuming ‘e’ because of that ambiguity, one approach could be —
syms x y
f(x,y) = (x^2 + 3*y^2)*exp(1-x^2-y^2);
figure
fcontour(f, [-1 1 -1 1], 'LevelList',[0:0.5:3], 'Fill','on')
colormap(turbo)
colorbar
axis('equal')
.
lateef
lateef 2023년 3월 25일
i tried using the fcontour with my current code and im getting an error messsage
lateef
lateef 2023년 3월 25일
ive attached my currrent code i want to add level curves too using fcountour the code gets an error message
If you want to use a function handle, my code changes to:
f = @(x,y) (x.^2 + 3*y.^2).*exp(1-x.^2-y.^2);
figure
fcontour(f, [-1 1 -1 1], 'LevelList',[0:0.5:3], 'Fill','on')
colormap(turbo)
colorbar
axis('equal')
That is the only change necessary. The 'Fill','on' is optional.
Your code would work with contour or contourf, although not with fcontour, since fcontour creates its own matrices and does not take them as arguments.
.

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

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

질문:

2023년 3월 24일

댓글:

2023년 3월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by