How to write code to plot graph of for this function

9 ビュー (過去 30 日間)
Rafae Ahmed
Rafae Ahmed 2020 年 2 月 4 日
回答済み: Tomás Cardadeiro 2021 年 11 月 17 日
I wanted to know how to plot my a graph for my function. The x-axis needs to be values of 'v' from from 1-10. The y-axis is the values of the function y(v). I want to label the x-axis: v [mol/m^3] and y-axis y(v). How would I write the code for this? Below is the some of the code I have written.
P=2020000;%P,R,a,b are all constants
R=8.314;
a=0.16330;
b=0.00002401;
v=[0:1:10];%range of v values for the x-axis
y=((R*T)/(v-b))+((a)/((v^2+(2*b*v)-b^2)))+P
plot(v,y)

回答 (3 件)

Sivakumar Selvam
Sivakumar Selvam 2020 年 2 月 4 日
P=2020000;%P,R,a,b are all constants
R=8.314;
a=0.16330;
b=0.00002401;
v=[0:1:10];%range of v values for the x-axis
y=((R*T)/(v-b))+((a)/((v^2+(2*b*v)-b^2)))+P
plot(v,y);
xlabel('v [mol/m^3]')
ylabel('y(v)')
  1 件のコメント
Rafae Ahmed
Rafae Ahmed 2020 年 2 月 4 日
Hi thanks for answering. But I am getting this error:
Error using /
Matrix dimensions must agree.
Error in assignment2 (line 6)
y=((R*T)/(v-b))+((a)/((v^2+(2*b*v)-b^2)))+P

サインインしてコメントする。


Prashanth Darla
Prashanth Darla 2020 年 2 月 4 日
編集済み: Prashanth Darla 2020 年 2 月 4 日
Hey,you're all good if you declare T and elemenmtwise operatorfor division and power (Here I used T as 1)
Here's the code I suggest for you
P=2020000;%P,R,a,b are all constants
R=8.314;
a=0.16330;
b=0.00002401;
T=1;
v=(1:1:10);
disp(v);
for i =v
%range of v values for the x-axis
y=(((R*T)./(i-b))+((a)./((i.^2+(2*b*i)-b.^2)))+P);
disp(y);
end
plot(v,y);
xlabel('v [mol/m^3]')
ylabel('y(v)')
Hope this solves the issue.
  1 件のコメント
Rafae Ahmed
Rafae Ahmed 2020 年 2 月 4 日
Hi,
I used this code but it is giving me the same value of for y(v) 2.0200e+6. Also the graph is not showing and line or curve when I run the code. Below is the what the formula should be, I wanted to make sure the way I wrote it in Matlab matches what it is normally:
Screen Shot 2020-02-04 at 9.15.32 AM.png
Also, what code do I need to write to show enough 'v' values where it will show where the line or curve on the graph touches the x-axis (the roots).

サインインしてコメントする。


Tomás Cardadeiro
Tomás Cardadeiro 2021 年 11 月 17 日
Hi i know its just a little too late but see if thats not you want
clc
clear all
P=2020000;%P,R,a,b are all constants
R=8.314;
a=0.16330;
b=0.00002401;
T=1;
y1=[];
v1=[];
for v=0:10%range of v values for the x-axis
y=((R*T)/(v-b))+((a)/((v^2+(2*b*v)-b^2)))+P;
y1=[y1 y];
v1=[v1 v]
end
plot(v1,y1)

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by