필터 지우기
필터 지우기

How Can I Resolve Plotting Error?

조회 수: 2 (최근 30일)
Avery-Ryan Ansbro
Avery-Ryan Ansbro 2022년 4월 17일
댓글: Avery-Ryan Ansbro 2022년 4월 18일
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일
Please post executable code so that others can help you.

댓글을 달려면 로그인하십시오.

답변 (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