Plot two lines on different graphs from integral

To=27+273.15; %%k
cao=0.1; %%mol/dm^3
k1=.01; %%dm^3/mol*s
tha=1;thb=1;
ha=-20000; hb=-15000; hc=-41000; %%cal/mol
cpc=30;cpa=15;cpb=15; %%cal/mol*k
sumtcp=tha*cpa+thb*cpb;
delcp=cpc-cpb-cpa;
dhrx=hc-hb-ha;
E=10000; %%cal/mol
R=1.987; %%cal/mol*k
vo=2;
fao=cao*vo;
cbo=cao;
ca=@(x) cao*(1-x);
cb=@(x) cbo*(1-x);
T=@(x) To+(-dhrx)*x/(sumtcp+delcp.*x) ;
k=@(x) k1*exp(E/R*(1/To-1/T(x)));
ra=@(x) -(k(x).*ca(x).*cb(x));
vpfr1=@(x) fao./(-ra(x));
vpfr=integral(vpfr1,0,.85);
>> xspan=0:.1:1;
>> plot(vpfr,xspan)
>>
I would like to plot x vs vpfr and T vs Vpfr on different graphs. With Vpfr being the x-axis
This gives me ablank graph

5 件のコメント

Rik
Rik 2020 年 4 月 24 日
Since vpfr is a scalar you are only plottin a single value. Is that what you mean?
Rodrigo Blas
Rodrigo Blas 2020 年 4 月 24 日
Yes. I dont want to just plot a single point. How do i make it plot the line ?
Ankit
Ankit 2020 年 4 月 24 日
編集済み: Ankit 2020 年 4 月 24 日
You have to convert your problem to as shown below. otherwise you will get only one value.
% Integrate the vector-valued function sin((1:5)*x) from 0 to 1:
Q = integral(@(x)sin((1:5)*x),0,1,'ArrayValued',true)
for plotting temp, just use the for loop:
T=@(x) To+(-dhrx)*x/(sumtcp+delcp.*x) ;
for i = 1:length(xspan)
Temp(i) = T(xspan(i)) ;
end
figure;plot(Temp,xspan);grid on;
Rik
Rik 2020 年 4 月 24 日
vpfr=integral(vpfr1,0,0.85,'ArrayValued',true);
That still returns a scalar.
@Rodrigo: you don't explain what you want to achieve, so it is difficult to give you good advice. How would you calculate the value of vpfr for a single value of xspan? Once that is clear we can help you extend it to an array.
Rodrigo Blas
Rodrigo Blas 2020 年 4 月 24 日
I want to plot x from 0 to 1 on the y axis and plot its corresponding vpfr value on the x axis.
ca=@(x) cao*(1-x);
cb=@(x) cbo*(1-x);
T=@(x) To+(-dhrx)*x/(sumtcp+delcp.*x) ;
k=@(x) k1*exp(E/R*(1/To-1/T(x)));
ra=@(x) -(k(x).*ca(x).*cb(x));
vpfr1=@(x) fao./(-ra(x));
vpfr=integral(vpfr1,0,.85);
Using the integral of the vpfr function.

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

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 24 日
編集済み: Ameer Hamza 2020 年 4 月 24 日

0 投票

I guess you are trying to do something like this. Note that I have varied x from 0 to 0.9, because at x=1, the integral diverges.
To=27+273.15; %%k
cao=0.1; %%mol/dm^3
k1=.01; %%dm^3/mol*s
tha=1;thb=1;
ha=-20000; hb=-15000; hc=-41000; %%cal/mol
cpc=30;cpa=15;cpb=15; %%cal/mol*k
sumtcp=tha*cpa+thb*cpb;
delcp=cpc-cpb-cpa;
dhrx=hc-hb-ha;
E=10000; %%cal/mol
R=1.987; %%cal/mol*k
vo=2;
fao=cao*vo;
cbo=cao;
ca=@(x) cao*(1-x);
cb=@(x) cbo*(1-x);
T=@(x) To+(-dhrx)*x./(sumtcp+delcp.*x); % <----- element-wise division should be used
k=@(x) k1*exp(E/R.*(1/To-1./T(x))); % <----- element-wise operators should be used
ra=@(x) -(k(x).*ca(x).*cb(x));
vpfr1=@(x) fao./(-ra(x));
x = 0:0.1:0.9;
vpfr = zeros(size(x));
for i=1:numel(x)
vpfr(i) = integral(vpfr1,0,x(i));
end
plot(x, vpfr);
figure;
plot(T(x), vpfr);

6 件のコメント

Rodrigo Blas
Rodrigo Blas 2020 年 4 月 24 日
Great! Thank You!
How would I do the same for vpfr vs T?
Ameer Hamza
Ameer Hamza 2020 年 4 月 24 日
Rodrigo, check the updated code. Which trying to plot T(x) vas vpfr, I found some other issues in your code. I have also corrected those. Please see my comment pointed out with "<-----"
Rodrigo Blas
Rodrigo Blas 2020 年 4 月 24 日
Thank you
Rodrigo Blas
Rodrigo Blas 2020 年 4 月 24 日
How would I do Vpfr vs T(x) in the same manner?
Rodrigo Blas
Rodrigo Blas 2020 年 4 月 24 日
Nevermind. I figured it out. THank you so much
Ameer Hamza
Ameer Hamza 2020 年 4 月 24 日
I am glad to be of help.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by