Changing parameters in a function to keep it the same.

2 views (last 30 days)
I have this function in which there are three inputs. l, the length of the rods, L the lattice spacing and h, the diameter of the rods. I would like to work out how much each of the other parameters must change to keep the function answer the same, if one parameter is changed. For example, if the lattice spacing doubles, I would like to know, how much the length and diameter of the rods must change to keep the function answer the same. I would like to do this for all three cases, (changing lattice spacing, changing diameter and changing length.)
I have tried to word this as best as I can so apolgies if it isnt clear. I can try and re-word if needs be. I am also fairly new to matlab so if this is obvious then i apologise.
Thank you in advance!
function dfun= disp_fun2(L,l,h)
omega= 2*pi*500;
rho=2700;
lambda=58e9;
mu=26e9;
rho_r = rho;
lambda_r = lambda;
mu_r = mu;
k = 6.9854e10;
kl=omega.*sqrt(rho./(lambda+2*mu));
kt=omega.*sqrt(rho./mu);
E_r=mu_r.*(3.*lambda_r+2.*mu_r)/(lambda_r+mu_r);
V=0.25*pi*h^2.*omega.*sqrt(E_r.*rho_r)*tan(l.*omega.*sqrt(rho_r./E_r));
%dfun=4*k.^2.*sqrt(k.^2-kl.^2).*sqrt(k.^2-kt.^2)-(2.*k.^2-kt.^2).^I2-...
%sqrt(k.^2/kt.^2 - kl.^2./kt.^2) .* ( V ./ (omega.*L.^2.*sqrt(rho.*mu)));
E=k/kt;
E2=E.*E;
r=kl./kt;
r2=r.*r;
dfun=4*E2 .* sqrt(E2-r2).*sqrt(E2-1)-(2.*E2-1).^2-...
sqrt(E2 - r2) .* ( V ./ (omega.*L.^2.*sqrt(rho.*mu)));

Answers (1)

Nipun
Nipun on 5 Oct 2023
Hi Aman,
I understand that you have a function that takes three arguments and returns an output based on the inputs, and you want to evaluate the behaviour of other parameters when a given parameter is double and the returned output value is fixed.
There are a few ways you can observe the bevaiour of other parameters given an equation. You may model your system as an equation using symbolic representation in MATLAB. Just remove the function name and add the following line:
syms L l h;
This will return dfunc as a symbol with value:
dfun =
-(16682039334976141143122512362065*h^2*pi*tan((906025378360265875*pi*l)/4611686018427387904))/(589587621165280919552*L^2)
Now from the equation, it is easy to see the dependency of the output on the input variables. For example, when L is doubled, the output is quartered, therefore we can either double h or find a suitable value for l using tan inverse.
You may also consider plotting the equation against a specific value of dfun and fixing some parameters. You can use the solve functionality to obtain a dependency, given a desired output. For instance,
>> solve(dfun==-2.2879e+10, L)
ans =
-(h*pi^(1/2)*((3336407866995228228624502472413*tan((906025378360265875*pi*l)/4611686018427387904))/674458759232023107921510400000)^(1/2))/2
(h*pi^(1/2)*((3336407866995228228624502472413*tan((906025378360265875*pi*l)/4611686018427387904))/674458759232023107921510400000)^(1/2))/2
Link to documentation:
  1. Create Symbolic Numbers, Variables, and Expressions - MATLAB & Simulink - MathWorks India
  2. Plot symbolic expression or function - MATLAB fplot - MathWorks India
  3. Equations and systems solver - MATLAB solve - MathWorks India
Hope this helps.
Regards,
Nipun

Categories

Find more on Historical Contests in Help Center and File Exchange

Products


Release

R2015b

Community Treasure Hunt

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

Start Hunting!