Effacer les filtres
Effacer les filtres

How Can I Resolve Plotting Error?

2 vues (au cours des 30 derniers jours)
Avery-Ryan Ansbro
Avery-Ryan Ansbro le 17 Avr 2022
Hello, I attempted to plot two functions. Here a version of what I tried to plot with simplified equations, since I don't think the equations are the issue here, just the coding jargon. All variables are predefined, with x_2 being an array of 99 values and temp being a constant:
clc; %clear the console
clear all; %clear all the variables
%%defitions
temp=2000;
x_2=0.01:0.01:0.99;
Gm_s=zeros(99);
Gm_l=zeros(99);
for i=1:99
x_1=1-x_2(i);
Ll=11760*temp*(x_1-x_2(i));
Ls=8366+*temp(x_1-x_2(i));
Gm_l(i)=(x_2(i)*Ll)+(x_1*Ll);
Gm_s(i)=(x_2(i)*Ls)+(x_1*Ls);
end
plot(x_2,Gm_s,'DisplayName','Solid G')
hold on
plot(x_2,Gm_l,'DisplayName','Liquid G')
legend
hold off
My resultant graph looks like this. I had attempted without the legend function and had still gotten a similar result.
I want a graph that shows how Gm_l and Gm_s vary with x_2. How do I fix this problem?
  1 commentaire
Chunru
Chunru le 18 Avr 2022
Please post executable code so that others can help you.

Connectez-vous pour commenter.

Réponses (1)

Chunru
Chunru le 18 Avr 2022
clc; %clear the console
clear all; %clear all the variables
%%defitions
temp=2000;
x_2=0.01:0.01:0.99;
% Get the correct size for Gm_s Gm_l
Gm_s=zeros(size(x_2));
Gm_l=zeros(size(x_2));
for i=1:99
x_1=1-x_2(i);
Ll=11760*temp*(x_1-x_2(i));
% Ls=8366+*temp(x_1-x_2(i)); % error here
Ls=8366*temp*(x_1-x_2(i));
Gm_l(i)=(x_2(i)*Ll)+(x_1*Ll);
Gm_s(i)=(x_2(i)*Ls)+(x_1*Ls);
end
whos
Name Size Bytes Class Attributes Gm_l 1x99 792 double Gm_s 1x99 792 double Ll 1x1 8 double Ls 1x1 8 double i 1x1 8 double temp 1x1 8 double x_1 1x1 8 double x_2 1x99 792 double
plot(x_2,Gm_s,'DisplayName','Solid G')
hold on
plot(x_2,Gm_l,'DisplayName','Liquid G')
legend
hold off
  1 commentaire
Avery-Ryan Ansbro
Avery-Ryan Ansbro le 18 Avr 2022
The site will not let me mark your answer as helpful or correct but thank you

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by