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

1 visualización (últimos 30 días)
Akhtar Jan
Akhtar Jan el 30 de Mzo. de 2022
Comentada: Arif Hoq el 30 de Mzo. de 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.

Respuesta aceptada

Arif Hoq
Arif Hoq el 30 de Mzo. de 2022
Editada: Arif Hoq el 30 de Mzo. de 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 comentarios
Arif Hoq
Arif Hoq el 30 de Mzo. de 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 el 30 de Mzo. de 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])

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Variables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by