How can I run this code I don't know where is the fault?

1 vue (au cours des 30 derniers jours)
Akhtar Jan
Akhtar Jan le 30 Mar 2022
Commenté : Arif Hoq le 30 Mar 2022
clc
close all
clf
k1 = 2;
k_1 = 1;
k2 = 1;
k3 = 2;
k_3 = 1;
k4 = 1;
St = 100;
K1 = (k_1+k2)/(k1*St);
K2 = (k_3+k4)/(k3*St);
E1t = 20;
E2t = 30;
v = (k2*E1t)/(k4*E2t);
P = ((v-1)-K2*(v+K1/K2))+sqrt((v-1)-K2*(v+K1/K2)^2+4*K2*v*(v-1))/2*(v-1);
S = St - P;
pt1 = plot(v,P,'r');
Warning: Imaginary parts of complex X and/or Y arguments ignored.
hold on
pt2 = plot(v, S,'g');
Warning: Imaginary parts of complex X and/or Y arguments ignored.

Réponse acceptée

Arif Hoq
Arif Hoq le 30 Mar 2022
Modifié(e) : Arif Hoq le 30 Mar 2022
As your output is a scalar value so you need to define it with Marker. and you are plotting only real values
k1 = 2;
k_1 = 1;
k2 = 1;
k3 = 2;
k_3 = 1;
k4 = 1;
St = 100;
K1 = (k_1+k2)/(k1*St);
K2 = (k_3+k4)/(k3*St);
E1t = 20;
E2t = 30;
v = (k2*E1t)/(k4*E2t);
P = ((v-1)-K2*(v+K1/K2))+sqrt((v-1)-K2*(v+K1/K2)^2+4*K2*v*(v-1))/2*(v-1);
S = St - P;
pt1 = plot(v,P,'o');
Warning: Imaginary parts of complex X and/or Y arguments ignored.
hold on
pt2 = plot(v, S,'*');
Warning: Imaginary parts of complex X and/or Y arguments ignored.
  4 commentaires
Arif Hoq
Arif Hoq le 30 Mar 2022
try this for imaginary and real value
plot(v,real(P),'o'); % real part of P
hold on
plot(imag(P),'s') % imaginary part of P
hold on
plot(v, real(S),'*'); % real part of S
hold on
plot(imag(S),'d') % imaginary part of S
xlim([0 2])
Arif Hoq
Arif Hoq le 30 Mar 2022
for continious graph use linspace
k1 = 2;
k_1 = 1;
k2 = 1;
k3 = 2;
k_3 = 1;
k4 = 1;
St = 100;
K1 = (k_1+k2)/(k1*St);
K2 = (k_3+k4)/(k3*St);
E1t = 20;
E2t = 30;
v = (k2*E1t)/(k4*E2t);
P = ((v-1)-K2*(v+K1/K2))+sqrt((v-1)-K2*(v+K1/K2)^2+4*K2*v*(v-1))/2*(v-1);
S = St - P;
t=linspace(0,5,100);
plot(t,real(P),'o'); % real part of P
hold on
% plot(t,imag(P),'s') % imaginary part of P
% hold on
plot(t, real(S),'*'); % real part of S
% hold on
% plot(t,imag(S),'d') % imaginary part of S
% xlim([0 2])

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Variables dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by