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

1 view (last 30 days)
Akhtar Jan on 30 Mar 2022
Commented: Arif Hoq on 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.

Arif Hoq on 30 Mar 2022
Edited: Arif Hoq on 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.
Arif Hoq on 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])