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

sixwwwwww
sixwwwwww 2013년 10월 11일
Hi Nikhil, you are getting two values of Kn in your first code(trial). Which value you want to pass to second function(loaddistr)?
Nikhil
Nikhil 2013년 10월 11일
Hey, Yes. I want to transfer Kn values from trial.m to loaddistr.m.
sixwwwwww
sixwwwwww 2013년 10월 11일
For Kn you get these two values 3.2307e5 and 3.5893e5. So you want to pass both values to loaddistr.m?
Nikhil
Nikhil 2013년 10월 11일
Yes and I also want to solve for loaddistr.
sixwwwwww
sixwwwwww 2013년 10월 11일
편집: sixwwwwww 2013년 10월 11일
Why don't you embed loaddistr.m code within trial.m code. Because calculations are performed sequentially. Also by passing two values of Kn you will not three but four values at the end as a result
Nikhil
Nikhil 2013년 10월 11일
Hey, as per your suggestion I tried following thing.. but the I got error as follows 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
??? function n = loaddistr( m ) | Error: Function definitions are not permitted in this context.
Nikhil
Nikhil 2013년 10월 11일
I just copy paste loaddistr.m in trial.m script .. and tried to run it.. but the error I got is
??? function n = loaddistr( m ) | Error: Function definitions are not permitted in this context.
sixwwwwww
sixwwwwww 2013년 10월 11일
wait i do it for you. Surely you can't define function like this. I do it wait
Nikhil
Nikhil 2013년 10월 11일
okay.

댓글을 달려면 로그인하십시오.

 채택된 답변

sixwwwwww
sixwwwwww 2013년 10월 11일

0 개 추천

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

Nikhil
Nikhil 2013년 10월 11일
Nopes. Your missing crucial point over here. n is non linear system of equations in m. I am trying to solve for this system of equations using fsolve and initial value m0. Kn term is used in one of this equations.
sixwwwwww
sixwwwwww 2013년 10월 11일
ok I come to it
Nikhil
Nikhil 2013년 10월 11일
the real problem is how to solve for system of equations while importing values from other function
sixwwwwww
sixwwwwww 2013년 10월 11일
We can pass Kn as fourth element in m0 in trial.m and in loaddistr.m we can separate m0 and Kn because there m0 elements are used individually. Do you agree?
Nikhil
Nikhil 2013년 10월 11일
let me try this
sixwwwwww
sixwwwwww 2013년 10월 11일
ok
Nikhil
Nikhil 2013년 10월 11일
now the problem is that. Kn itself is the vector. So we will have problem in extracting its value in loaddistr.m
Nikhil
Nikhil 2013년 10월 11일
I am getting an error for that. ??? Undefined function or method 'm0' for input arguments of type 'double'.
Error in ==> loaddistr at 6 Kn=m0(4);
Error in ==> fsolve at 248 fuser = feval(funfcn{3},x,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
trial.m will be like this:
%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, Kn(1)];
p=fsolve(@loaddistr,m0);
and loaddistr.m will be like this:
function n = loaddistr(m)
Fr=8900;
Pd=0.015;
Z=9;
Kn=m(4);
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
sixwwwwww
sixwwwwww 2013년 10월 11일
now you can test
Nikhil
Nikhil 2013년 10월 11일
??? Undefined function or method 'm0' for input arguments of type 'double'.
Error in ==> loaddistr at 6 Kn1=m0(4);
Error in ==> fsolve at 248 fuser = feval(funfcn{3},x,varargin{:});
Caused by: Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
This is the error I am getting. The problem is that fsolve solves for m. Hence I guess we can not put values Kn value in m0. Whats your opinion.
sixwwwwww
sixwwwwww 2013년 10월 11일
But I am not getting any error. Are you using codes I just posted above?
Nikhil
Nikhil 2013년 10월 11일
Hey, Thanks that worked. There was small typo. But now the issue is that I will have to use for loop to solve loaddistr for each value of Kn(i). right? or is there any efficient way to do it?
sixwwwwww
sixwwwwww 2013년 10월 11일
The thing is that for each value of Kn you will get different set of equations which you will need to solve. So you will have to use for loop inevitably. Wish you good luck
Nikhil
Nikhil 2013년 10월 11일
Haha. I will work that out. Anyways thanks a lot for your help.
sixwwwwww
sixwwwwww 2013년 10월 11일
You are always welcome. If you have further problems you can share as well. Good luck!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

태그

질문:

2013년 10월 10일

댓글:

2013년 10월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by