make code more rigorous
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
David Hill
on 10 Feb 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('')
0 Comments
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!