Plotting the solution of multi-variable non-linear equations (solved using fsolve).

These are the equations:
function [fval]= ptfunc(X)
Tcell=X(1);
Pcell=X(2);
Qh=X(3);
Pteg=X(4);
alpha = 0.95;
A = (0.04)^2;
epsilon = 0.88;
sigma = 5.69*10^(-8);
Ta = 298.15;
u=(0.003+1/5)^-(1);
ns = 0.10;
theta = 0.0011;
An=6.4*10^-7;
Hn=0.01;%:0.01:0.06;
N=62;
S=185*10^-6;
rho=10^-5;
den=2*rho;
k=1.5;
Z=(S^2)/(rho.*k);
Tc=298;
r=0.2;
n=0.0001;
hc=0.00009;
num2=2*r*hc;
G=500;
fval(1,1)= -Qh+ alpha*G*A-u*A*(Tcell-Ta)-epsilon*sigma*A*((Tcell.^4)-(Ta^4))-Pcell;
fval(2,1)= -Pcell+ alpha*G*A*ns.*(1-theta.*(Tcell - 298));
fval(3,1)= -Qh + (k*An*N/Hn)*(1-Z*(3*Tcell+Tc)/8)*(Tcell-Tc);
fval(4,1)= -Pteg+(S^2)*An*N*((Tcell-Tc)^2)./(den.*(n+Hn).*(1+num2./Hn).^2);
I need to plot the varaibles with respect to G. How do I do that?

2 件のコメント

Stephan
Stephan 2019 年 4 月 9 日
G is a scalar - its value is 500 - so you would plot 4 single points - one for each result from fsolve. Is this what you want to do?
Yavar Hayat
Yavar Hayat 2019 年 4 月 9 日
No. I want to the values of G so as to plot the four variables accordglingly.

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

 採用された回答

Torsten
Torsten 2019 年 4 月 9 日

0 投票

function main
G = linspace(250,750).';
X0 = [1,1,1,1];
for i=1:numel(G)
sol = fsolve(@(X)ptfunc(X,G(i)),X0);
x(i,:) = sol;
X0 = sol;
end
plot(G,x(:,1))
end
function fval = ptfunc(X,G)
Tcell=X(1);
Pcell=X(2);
Qh=X(3);
Pteg=X(4);
alpha = 0.95;
A = (0.04)^2;
epsilon = 0.88;
sigma = 5.69*10^(-8);
Ta = 298.15;
u=(0.003+1/5)^-(1);
ns = 0.10;
theta = 0.0011;
An=6.4*10^-7;
Hn=0.01;%:0.01:0.06;
N=62;
S=185*10^-6;
rho=10^-5;
den=2*rho;
k=1.5;
Z=(S^2)/(rho.*k);
Tc=298;
r=0.2;
n=0.0001;
hc=0.00009;
num2=2*r*hc;
%G=500;
fval(1,1)= -Qh+ alpha*G*A-u*A*(Tcell-Ta)-epsilon*sigma*A*((Tcell.^4)-(Ta^4))-Pcell;
fval(2,1)= -Pcell+ alpha*G*A*ns.*(1-theta.*(Tcell - 298));
fval(3,1)= -Qh + (k*An*N/Hn)*(1-Z*(3*Tcell+Tc)/8)*(Tcell-Tc);
fval(4,1)= -Pteg+(S^2)*An*N*((Tcell-Tc)^2)./(den.*(n+Hn).*(1+num2./Hn).^2);
end

4 件のコメント

Yavar Hayat
Yavar Hayat 2019 年 4 月 9 日
I get one graph using your code. How do I get all four or choose one of them.
Torsten
Torsten 2019 年 4 月 9 日
plot(G,x)
instead of
plot(G,x(:,1))
Walter Roberson
Walter Roberson 2019 年 4 月 10 日
However, it is working. The reason it does not look like it is working is that one of the results is on the order of 300, and two of them are on the order of 0.1, and the last of them is on the order of 0.01 . You simply cannot see anything in 3 of the 4 lines because they are insignificant on the scale of the first plot.
You could use subplot() to break the values out.
If you have a new enough MATLAB you could use stackedplot()
I got it by using
plot(G,x(:,1))
plot(G,x(:,2))
etc.
Thank you.

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2017b

タグ

質問済み:

2019 年 4 月 9 日

コメント済み:

2019 年 4 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by