Clear Filters
Clear Filters

How Can I Resolve Plotting Error?

2 views (last 30 days)
Avery-Ryan Ansbro
Avery-Ryan Ansbro on 17 Apr 2022
Commented: Avery-Ryan Ansbro on 18 Apr 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 Comment
Chunru
Chunru on 18 Apr 2022
Please post executable code so that others can help you.

Sign in to comment.

Answers (1)

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

Sign in to comment.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!