フィルターのクリア

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 Center および File ExchangeGet 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