Matlab Introduction Course for Undergrads

Hey, I have following function
x = linspace(-0.5,0.5);
y = linspace(-0.5,0.5);
[X,Y] = meshgrid(x,y);
V = 4*(((exp(-20*(((X-0.25)^2) + (Y-0.25)^2)))) + exp(-20*(((X-0.25)^2 + (Y-0.75)^2))) + exp(-20*(((X-0.75)^2 + (Y-0.5)^2))));
figure
contour(X,Y,V,'ShowText','on')
I want to display the function text so I can debug, because Matlab only outputs arrays with zeros. So something is wrong with how I typed in the function.
i.e
Is this possible in MATLAB 2016b?
Thank you

댓글 수: 5

Adam
Adam 2016년 9월 23일
Simplest option would probably be to split it across a number of lines with intermediate variables. Maths all on one line with so many brackets may look neat and space-saving, but it can be more trouble than it is worth when it doesn't work correctly.
Stephen23
Stephen23 2016년 9월 23일
@Hakan Ole Ensrud Abediy: Splitting this onto several intermediate calcaultions, exactly as Adam has suggested, will be the simplest answer. Then you can check (by hand) that each intermediate step is correct.
José-Luis
José-Luis 2016년 9월 24일
Apparently, live script will prettify whatever equation you insert. That could be another way to check.
Especially useful if you are familiar with Latex.
Rena Berman
Rena Berman 2017년 9월 14일
(Answers Dev) Restored edit
Rena Berman
Rena Berman 2017년 12월 26일
(Answers Dev) Restored edit

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

답변 (2개)

Walter Roberson
Walter Roberson 2016년 9월 24일

0 개 추천

Your bug is that you used the ^ operator instead of the .^ operator. For a square matrix Z, Z^2 is Z*Z, the matrix algebraically multiplied by itself, whereas you want Z.*Z, which is each element multiplied by itself.
shegaw mamo
shegaw mamo 2019년 8월 16일

0 개 추천

function dx = cancerhealthcells(~, x)
dx = [2; 1];
L=15;
ommega=50
alpha1 = 0.1;
alpha2 = 0.45;
kappa1 = 0.65;
kappa2 = 1;
beta1 = 0.11;
beta2 = 0.15;
epsilon = 0.05;
gamma = 0.35;
dx(1) = alpha1*x(1)-alpha1*x(1).^2./kappa1-beta1*x(1)*x(2)-epsilon*gamma*x(1);
dx(2) = alpha2*x(2)-alpha2*x(2).^2./kappa2-beta2*x(1)*x(2)-gamma*x(2);
Question: Ommega and L are not in the system of equation. How we can develop matlab syntax including ommega and L using ode45?

댓글 수: 1

What leads you to expect that they should be present?

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

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2016년 9월 23일

댓글:

2019년 8월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by