Conversion of C code to Matlab code

15 visualizzazioni (ultimi 30 giorni)
Karim Ayman
Karim Ayman il 16 Dic 2022
Commentato: Jan il 16 Dic 2022
Hello,
I have a code written by C , Can anyone write it in Matlab script form, Please ?
#include <stdio.h>
#include <stdlib.h>
int main()
{ float pr=0.734,n=1.413*pow(10,-5),ts=12,to,nu,re,h,q,v,l=10,w=5,k=0.02428;
for(v=2;v<=50;v+=2)
{ re=(v*(0.277778)*l)/n;
nu=((0.037*pow(re,0.8))-871)*pow(pr,0.333333);
h=(nu*k)/l;
printf("\n\n(velocity : %f(km/h) )\t",v);
printf(" (rynold : %f)\t",re);
printf("(nusselt : %f)\t",nu);
printf(" (h : %f(w/m^2*k))\n",h);
for(to=0;to<=10;to++)
{
if(ts>to)
q=h*(l*w)*(ts-to);
else q=h*(l*w)*(to-ts);
printf("\t\t\tthe heat loss from surface is : %f\n",q);
}
}
return 0;
}

Risposta accettata

Jan
Jan il 16 Dic 2022
Modificato: Jan il 16 Dic 2022
pr = 0.734;
n = 1.413e-5;
ts = 12
l = 10;
w = 5;
k =0.02428;
for v = 2:2:50
re = (v * 0.277778 * l) / n;
nu = (0.037 * re^0.8 - 871) * pr^0.333333;
h = (nu*k) / l;
fprintf("\n\n(velocity : %f(km/h) )\t",v);
fprintf(" (rynold : %f)\t",re);
fprintf("(nusselt : %f)\t",nu);
fprintf(" (h : %f(w/m^2*k))\n",h);
for to = 0:10
if ts > to
q = h * l * w * (ts-to);
else
q = h * l * w * (to-ts);
end
fprintf("\t\t\tthe heat loss from surface is : %f\n", q);
end
end
  2 Commenti
Karim Ayman
Karim Ayman il 16 Dic 2022
Thanks a lot, my friend
Jan
Jan il 16 Dic 2022
You are welcome. Do you see, that this was easy?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB Coder in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by