How Can I Resolve Plotting Error?

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

Chunru
Chunru 2022-4-18
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 个评论
Avery-Ryan Ansbro
Avery-Ryan Ansbro 2022-4-18
The site will not let me mark your answer as helpful or correct but thank you

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by