Finding unknown values of a variable that corresponds to another known variable within one equation
2 次查看(过去 30 天)
显示 更早的评论
I wasn't sure how to word that question more clearly so sorry about that. I have a design problem.
This is a function that is to be used in another script file:
function x = frsp_sdof(t)
% Free response function of a SDOF system
global m c k
global x0 v0
% m = mass in [kg or slug]
% c = damping coefficient in [N-s/m or lb-s/ft]
% k = stiffness in [N/m or lb/ft]
% x0 = initial displacement in [m or ft]
% v0 = initial velocity in [m/s or ft/s]
wn = sqrt(k/m); % natural frequency ("omega_n")
zeta = c/2/sqrt(k*m); % damping ratio
wd = wn*sqrt(1-zeta^2); % damped natural frequency ("omega_d")
if zeta == 1;
x = x0*exp(-wn*t) + (v0+wn*x0)*t.*exp(-wn*t); % critically damped case
else
x = exp(-zeta*wn*t)*(x0*cos(wd*t)+(v0+zeta*wn*x0)/wd*sin(wd*t));
end
I originally ran a for loop for multiple values of c and for only one value of k. I used this and fzero to find a minimum time value in this code:
x0 = 1;
v0 = 0;
c_data2 = [2:30]*1e3;
te_vec = zeros(1,length(c_data2));
for j=1:length(c_data2)
c = c_data2(j);
vel = derivative(@(t) frsp_sdof(t)); %defines the velocity function for the calculation below
E2 = @(t)((0.5*k*frsp_sdof(t).^2 + 0.5*m*vel(t).^2)/E0)-e; %incorporates the 5% displacement into the equation
te_vec(j) = fzero(E2, [0,2]);
end
I was able to find a minimum value of te within that te_vec variable. Now I have to use this minimum value to find corresponding ranges of c and k values that will lead to my minimum te. I can choose whichever range for k that I want and use that to find the c-values when my t-value is known. My problem is that my code isn't working.
k_data = [72:100]*1e3; %sets k_data as a vector from 72000 to 100000
e = 0.05; %instant when energy first dissipated
t = 0.2924; %min te value obtained from part b
c_data3 = zeros(1,length(k_data));
for j=1:length(k_data)
k = k_data(j);
E0 = 0.5*k*x0^2 + 0.5*m*v0^2; %energy equation
vel = derivative(@(t) frsp_sdof(t)); %defines the velocity function for the calculation below
E2 = @(c)((0.5*k*frsp_sdof(t).^2 + 0.5*m*vel(t).^2)/E0)-e; %incorporates the 5% displacement into the equation
c_data3(j) = fzero(E2, [0,2]);
end
Whenever I attempt to run this, I get an error:
>> project1c Error using fzero (line 273) The function values at the interval endpoints must differ in sign.
Error in project1c (line 24) c_data3(j) = fzero(E2, [0,2]);
Can anyone point in me in the right direction on how to find a range of c-values for my given range of k-values that corresponds to my minimum te = .2924s?
2 个评论
Walter Roberson
2016-11-12
I am confused about how the two segments above fit together, the one starting with x0 = 1; and the second with k_data assignment ?
Also, what is derivative() ?
It would be easier if you attached your source files
Daniel kiracofe
2016-11-13
Agree with Walter. We need to know what derivative() is. As far as I understand, that is not a built-in matlab function.
Also, may not be related to your actual question, but as a general programming practice, global variables are not recommended. Use them sparingly, and only when you absolutely cannot do it another way. In this case, it would be better if you had a four varaiable function frsp_sdof(t,m,c,k). Then when you create E2 = @(t)((0.5*k*frsp_sdof(t,m,c,k).^2 + 0.5*m*vel(t).^2)/E0)-e;, the function E2 remembers the values of m, c, and k that were present at the time the function was created, and will keep those same values every time it is called. This is called a "closure".
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!