How can I solve the function numerically for changing Prandtl Numbers ? I couldn't handle this with a for loop inside of a function.
3 ビュー (過去 30 日間)
古いコメントを表示
First of all, Hi to everyone. I hope you're okay in these days.
I would like to have a temperature distrubution for 5 different Prandtl numbers but I failed. The for loop that I created is not working. The function only takes the last index, so the last prandtl number is taken, and calculations have done according to this Prandtl number.
But I want to have the solution for different Prandtl Numbers and plot all of the solutions according to eta values.
My question is, the most important one here is;
1.How can I have solutions for different Prandtl numbers ?+++
and less importantly ,how can I plot all the solutions in a single graph ? ---
Have a nice and healty days.
This is my code:
function [Tstar]=Tstar_bools_(a,b,N)
if nargin<3,a=0;b=5; N=1600; end
eta = (0:0.2:b);
numberofeta=length(eta);
A = zeros(numberofeta,2);
B=ones(numberofeta,2);
for k = 1:numberofeta
h=(eta(k)-a)/N;
sum=(h/90)*f(a)+(h/90)*f(eta(k));
for i=1:N-1
x(i)=a+(i*h);
sum=sum+((2*h)/180)*(7*f(x(i))+32*f(x(i)+h/4)+12*f(x(i)+(2*h)/4)+32*f(x(i)+(3*h)/4)+7*f(x(i)+h));
A(k,1)=eta(k);
A(k,2)=sum;
B(1:k,2)=A(numberofeta,2);
end
end
A
% B
Tstar = A./B;
% Tstar;
% plot(Tstar(:,1), Tstar(:,2:end),'ro-')
end
function fx = f(x)
Pr=[0.7 1 3 7 13];
for i = 1:1:5
fx = (2*10^-5*x - 0.0011*x + 0.0163*x - 0.0843*x + 0.0824*x + 0.3177).^(Pr(i));
end
end
% function fx = f(x)
% fx = (2*10^-5*x - 0.0011*x + 0.0163*x - 0.0843*x + 0.0824*x + 0.3177)^(13);
% end
0 件のコメント
採用された回答
Alan Stevens
2021 年 5 月 3 日
Like this?
a = 0; b = 5; N = 1600;
eta = (0:0.2:b);
numberofeta=length(eta);
A = zeros(numberofeta,6); %%%%%%%%
B=ones(numberofeta,6); %%%%%%%%
for k = 1:numberofeta
h=(eta(k)-a)/N;
sum=(h/90)*f(a)+(h/90)*f(eta(k));
for i=1:N-1
x(i)=a+(i*h);
sum=sum+((2*h)/180)*(7*f(x(i))+32*f(x(i)+h/4)+12*f(x(i)+(2*h)/4)+32*f(x(i)+(3*h)/4)+7*f(x(i)+h));
A(k,1)=eta(k);
A(k,2:6)=sum; %%%%%%%%%%
B = A(numberofeta,:); %%%%%%%
end
end
Tstar = A./B;
Tstar;
plot(Tstar(:,1), Tstar(:,2:end),'o-')
function fx = f(x)
Pr=[0.7 1 3 7 13];
for i = 1:1:5
fx(i) = (2*10^-5*x - 0.0011*x + 0.0163*x - 0.0843*x + 0.0824*x + 0.3177).^(Pr(i)); %%%%%%
end
end
1 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!