Effacer les filtres
Effacer les filtres

make code more rigorous

1 vue (au cours des 30 derniers jours)
Muhammad Choudhury
Muhammad Choudhury le 10 Fév 2022
I have two seperate functions, fR1 AND fR2 however i would like to combine it into one function as i have to seperature function files.
currently i have this code to calculate rho1 and rho2
Any idea on how to combine it and make it more efficient
clear;clc
L = 20
A = 230
dT =[100:1:120]
a = 0.0039
rho1 = 0.0178
rho2 = 0.0170
a2 = 4.3e-3
b2 = 0.6e-6
rho = rho1*(1+a*dT)
rhoo = rho2*(1+a*dT+b2*(dT).^2)
R1 = fR1(rho,L,A)
R2 = fR2(rhoo,L,A)
hold on
plot(dT,R1)
plot(dT,R2)
xlabel('Temperature')
ylabel('Resistivity')
legend('')
the 2 function filed i have are essential the same thing:
fR1
function R = fR1(rho,L,A)
R = rho*L/A
end
fR2
function R = fR2(rhoo,L,A)
R = rhoo*L/A
end

Réponses (1)

David Hill
David Hill le 10 Fév 2022
Why have functions if you only call them once?
L = 20
A = 230
dT =[100:1:120]
a = 0.0039
rho1 = 0.0178
rho2 = 0.0170
a2 = 4.3e-3
b2 = 0.6e-6
rho = rho1*(1+a*dT)
rhoo = rho2*(1+a*dT+b2*(dT).^2)
R1 = rho*L/A;
R2 = rhoo*L/A;
hold on
plot(dT,R1)
plot(dT,R2)
xlabel('Temperature')
ylabel('Resistivity')
legend('')

Community Treasure Hunt

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

Start Hunting!

Translated by