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?

 Risposta accettata

Star Strider
Star Strider il 6 Giu 2020
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 Commenti

Ani Asoyan
Ani Asoyan il 6 Giu 2020
it gives the same error :/
Error using /
Matrix dimensions must agree.
Error in sev (line 30)
N(a) = (q*b*e/a-d*e)/((q^2)*(e^2)/a+2*e*g)
Note : I commented-out this line so that it does not execute:
% a=1:1:5;
So the code I posted with that change runs without error (in R2020a) and produces:
Remove (or comment-out) the ‘a’ assighment as I did, and my code works.
Ani Asoyan
Ani Asoyan il 6 Giu 2020
Thank you! It worked
Star Strider
Star Strider il 6 Giu 2020
As always, my pleasure!

Accedi per commentare.

Più risposte (1)

madhan ravi
madhan ravi il 6 Giu 2020
Naming a variable pi is a bad idea
doc pi

3 Commenti

Ani Asoyan
Ani Asoyan il 6 Giu 2020
ok but the problem remains
madhan ravi
madhan ravi il 6 Giu 2020
a=1:5 should be after N(a)... and implying ./
Ani Asoyan
Ani Asoyan il 6 Giu 2020
Thank you! it works

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by