How to link two functions
    5 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Hello all,
I am want to link following two programs: In first program(trial.m), I am calling fsolve function to solve for system of non linear equations which is stored in second function loaddistr. The two functions trial.m and loaddistr.m are as follows:
%trial curvesumi=0.2017; curvesumo=0.1377; distar=0.6031; dostar=0.6577; mateprop=1e-4*[0.1011 0.0910];
ki=(2/(curvesumi*distar))^(3/2).*curvesumi./(1.5.*mateprop);
ko=(2/(curvesumo*dostar))^(3/2).*curvesumo./(1.5.*mateprop);
Kn=(1./((1./ki).^(1/1.5)+(1./ko).^(1/1.5))).^1.5;
m0=[0.35,0.15,0.05];
p=fsolve(@loaddistr,m0);
function n = loaddistr( m ) Fr=8900; Pd=0.015; Z=9;
Kn=3.5893e+005;
Jr=[0.1156,0.1590,0.1892,0.2117,0.2288,0.2416,0.2505,0.2559,0.2576,0.2546,0.2289,0.1871,0.1339,0.0711];
eps=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.25, 1.67, 2.5, 5.0];
n=[m(1)-0.5*(1-0.5*Pd/m(3));
m(3)-Pd/2-(Fr/(Z*Kn*m(2)))^(1/1.5);
m(2)-spline(eps,Jr,m(1))];
end
If you notice I am using Kn term in both programs. I want to transfer this Kn value directly from trial.m to loaddistr.m, without separately specifying it in loaddistr.m So can someone please guide me about the code which will allow me to solve for loaddistr.m by using the Kn value from trial.m.
Thanks in advance,
Nikhil
9 Commenti
  sixwwwwww
      
 il 11 Ott 2013
				wait i do it for you. Surely you can't define function like this. I do it wait
Risposta accettata
  sixwwwwww
      
 il 11 Ott 2013
        Hey here is your merged code:
curvesumi = 0.2017; 
curvesumo = 0.1377; 
distar = 0.6031; 
dostar = 0.6577; 
mateprop = 1e-4 * [0.1011 0.0910];
ki = (2 / (curvesumi * distar)) ^ (3 / 2) .* curvesumi ./ (1.5 .* mateprop);
ko = (2 / (curvesumo * dostar)) ^ (3 / 2) .* curvesumo ./ (1.5 .* mateprop);
Kn = (1 ./ ((1 ./ ki) .^ (1 / 1.5) + (1 ./ ko) .^ (1 / 1.5))) .^ 1.5;
m0 = [0.35, 0.15, 0.05];
Fr = 8900; 
Pd = 0.015; 
Z = 9;
Jr = [0.1156, 0.1590, 0.1892, 0.2117, 0.2288, 0.2416, 0.2505, 0.2559, 0.2576, 0.2546, 0.2289, 0.1871, 0.1339, 0.0711];
eps = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.25, 1.67, 2.5, 5.0];
n = [m0(1) - 0.5 * (1 - 0.5 * Pd / m0(3));
   m0(3) - Pd / 2 - (Fr / (Z * Kn(1) * m0(2))) ^ (1 / 1.5); % for first value of Kn
   m0(3) - Pd / 2 - (Fr / (Z * Kn(2) * m0(2))) ^ (1 / 1.5); % for second value of Kn
   m0(2) - spline(eps, Jr, m0(1))];
16 Commenti
  sixwwwwww
      
 il 11 Ott 2013
				You are always welcome. If you have further problems you can share as well. Good luck!
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

