What's wrong with my code?

조회 수: 2 (최근 30일)
Ani Asoyan
Ani Asoyan 2020년 6월 6일
댓글: Star Strider 2020년 6월 6일
here's my code..
syms a
b=2; e=0.9; q=0.4; g=0.6; k=0; d=0.5;
a=1:1:5;
N(a) = (q*b*e/a-d*e)/((q^2)*(e^2)/a+2*e*g)
pi(a)=(b-q*N*e)/a
m=N(a)
n=pi(a)
plot (a,N(a),'b')
hold on
plot (a, pi(a),'red')
When I run it, it gives me these errors.
Error using /
Matrix dimensions must agree.
Error in sev (line 31)
N(a) = (q*b*e/a-d*e)/((q^2)*(e^2)/a+2*e*g)
When I use "./", it plots only pi, but N is on x axis fixed at 0, what can I do to make it work?

채택된 답변

Star Strider
Star Strider 2020년 6월 6일
Try this:
syms a
b=2; e=0.9; q=0.4; g=0.6; k=0; d=0.5;
% a=1:1:5;
N(a) = (q*b*e/a-d*e)/((q^2)*(e^2)/a+2*e*g)
fpi(a)=(b-q*N*e)/a
m=N(a)
n=fpi(a)
figure
fplot (N(a),[1 5],'b')
hold on
fplot (fpi(a), [1 5],'red')
hold off
.
  댓글 수: 5
Ani Asoyan
Ani Asoyan 2020년 6월 6일
Thank you! It worked
Star Strider
Star Strider 2020년 6월 6일
As always, my pleasure!

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

추가 답변 (1개)

madhan ravi
madhan ravi 2020년 6월 6일
Naming a variable pi is a bad idea
doc pi
  댓글 수: 3
madhan ravi
madhan ravi 2020년 6월 6일
a=1:5 should be after N(a)... and implying ./
Ani Asoyan
Ani Asoyan 2020년 6월 6일
Thank you! it works

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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by