Find roots of a function with multiple inputs

I am trying to use fzero to find roots of an equation. In the function, tw, tf and b are variables with a set value, Mx is a vector where I hope to use a for loop to repeat the fzero function to find roots with different Mx values. I dont know how to input the values or even if this is the right way to approach this problem.
function y=f(d,Mx,tw,tf,b)
y=355/Mx*(d^2*tw/12+tf^3*b/6+tf*b*(d+tf)^2/2)-d/2+tf

Answers (1)

And you want to solve for d ?
syms d Mx tw tf b
y = sym('355')/Mx*(d^2*tw/sym('12')+tf^3*b/sym('6')+tf*b*(d+tf)^2/sym('2'))-d/sym('2')+tf;
sol_d = solve(y==0,d)
sol_d = 
f1 = matlabFunction(sol_d(1));
f2 = matlabFunction(sol_d(2));
Mx = 4;
b = 2;
tf = 4;
tw = 20;
d1 = f1(Mx,b,tf,tw)
d2 = f2(Mx,b,tf,tw)

1 Comment

After that you can subs() a vector of Mx values into sol_d to get the solutions relative to those Mx values.

Sign in to comment.

Categories

Find more on Optimization in Help Center and File Exchange

Products

Release

R2021b

Asked:

on 11 Mar 2022

Edited:

on 11 Mar 2022

Community Treasure Hunt

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

Start Hunting!