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

1 次查看(过去 30 天)
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.

采纳的回答

Arif Hoq
Arif Hoq 2022-3-30
编辑:Arif Hoq 2022-3-30
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 个评论
Arif Hoq
Arif Hoq 2022-3-30
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 2022-3-30
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])

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by