why when i run code this error fv(:,1) = funfcn(x,varargin{:}) ?
Show older comments
global Nt Lf
Nt = 14;
Lf = 3.00;
d = 0.081;
OD = 0.800;
x_start = [ d OD ];
[ x_solution, min_val ] = fminsearch( 'pr02_spring', x_start )
d = x_solution(1);
OD = x_solution(2)
rho = 0.28;
G = 11.7e6;
Lw = 1.5;
D = OD - d;
w = rho * ( pi*d*d/4 ) * (pi*D) * Nt;
ID = D - d;
Na = Nt - 2;
k = d*d*d*d*G / (8*D*D*D*Na);
Fw = k * ( Lf - Lw );
Ls = Nt * d;
Fs = k * ( Lf - Ls );
C = D / d;
Ks = 1 + 0.5/C;
tau = Ks*8*Fs*D / (pi*d*d*d);
Sut = 184649 * ( d ^ -0.1625 );
Sys = 0.45 * Sut;
Nfs = Sys / tau;
disp( ' d OD Nt Lf weight' )
disp( ' [inch] [inch] [inch] [lbf]' )
disp( [ d OD Nt Lf w ] )
disp( ' ID k Fw Ls Nfs' )
disp( ' [in] [lbf/in] [lbf] [inch]' )
disp( [ ID k Fw Ls Nfs ] )
7 Comments
Guillaume
on 10 Jul 2018
What is the error. Post the full text, everything in red.
Most likely the error comes from pr02_spring for which you haven't supplied the code.
muhammad jassim
on 10 Jul 2018
Guillaume
on 10 Jul 2018
Well, there you go! Where is the pr02_spring.m file?
Note that the 3rd character is a zero, not an oh.
muhammad jassim
on 10 Jul 2018
Jan
on 10 Jul 2018
@muhammad jassim: Guillaume asked, where the file pr02_spring.m is. Answering this question would allow to solve the problem. Using 'W' instead does not change anything and it is not clear, why you assume this.
muhammad jassim
on 10 Jul 2018
Please do not close questions, which got an answer.
The nature of this forum is to share solutions in public. Therefore neither email or whatsapp is really welcome. You did not answer the questions for clarifications yet, so you do not let us you help.
I still assume the solution is very easy and you simply do not save the text of the functions, where it is expected. You can simply post your code here. But remember that the readers are not interested in this question anymore, because you have marked it as solved already by accepting an answer.
Accepted Answer
More Answers (1)
Jan
on 10 Jul 2018
Provide the function handle to the existing function as 1st input to fminsearch. Using a char vector is allowed for backward compatibility, but this is outdated for 20 years now.
Simply replace 'pr02_spring' by e.g. @yourFcn, where "yourFcn" is the name of a function inside Matlab's path. See also:
doc addpath
doc pathtool
2 Comments
muhammad jassim
on 10 Jul 2018
Jan
on 10 Jul 2018
What is "it"? Defining a valid function handle is the only reliable way. If you state, that it does not work, show us, what you have tried and which error message you get. What did you used instead of "yourFcn"?
You did not answer Guillaume's questions for clarifications also. But now you have selected his answer as "accepted", which means, that the problem is solved. Is it?
Categories
Find more on Function Creation 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!