# Problem solving system of nonlinear equations with fsolve trying to change inputs

2 views (last 30 days)
Nathaniel H Werner on 11 May 2019
I am trying to solve a system of six nonlinear equations using fsolve (see below). There are additional parameters in my equations that I would like to be able to input into the system or change the functionality without having to go into my function and manually editing them each time.
They are F, rho, and A. Right now I have set them all to 1, and I am able to get a solution so at least the script is running correctly.
function f = pressXmanifold(x)
F = [1,1,1];
rho = 1;
A = 1;
f(1) = x(1)-x(3) - ...
1/2*rho*(x(4)/F(1))^2*...
A*(x(4)/x(6)*F(3)/F(1))^(-2)*...
(1+(F(3)/F(1))^2+3*(F(3)/F(1))^2*((x(4)/x(6))^2-(x(4)/x(6))));
f(2) = x(2)-x(3) - ...
1/2*rho*(x(5)/F(2))^2*...
A*(x(5)/x(6)*F(3)/F(2))^(-2)*...
(1+(F(3)/F(2))^2+3*(F(3)/F(2))^2*((x(5)/x(6))^2-(x(5)/x(6))));
f(3) = x(1) - x(3);
f(4) = x(2) - x(3);
f(5) = x(4) - x(5);
f(6) = x(4)+x(5) - x(6);
end
1. For F I would want to be able to input any 1 x 3 array into my function.
2. For rho I would want to input a value as well.
3. For A, it would have to change with the iterations based on the following criteria (given as an if statement).
if F(3)/F(1) <= 0.35 && x(3)/x(2) <= 1
A = 1;
elseif F(3)/F(1) > 0.35 && x(3)/x(2) <= 0.4
A = 0.9*(1-x(3)/x(2));
elseif F(3)/F(1) > 0.35 && x(3)/x(2) > 0.4
A = 0.55;
end
For now I've only tried dealing with the first two parameters. f = pressXmanifold(x,F,rho) and removing the first two lines in my function.
But when I try to follow the instructions on the MathWorks site
options = optimoptions('fsolve','Display','none','PlotFcn',@optimplotfirstorderopt);
fun = @pressXmanifold;
x0 = [1,1,1,1,1,1];
x = fsolve(fun,x0,F,rho,options)
Unable to perform assignment because dot indexing is
not supported for variables of this type.
Error in createOptionFeedback (line 33)
options.(stopTestOptions{k}) = [];
Error in prepareOptionsForSolver (line 57)
optionFeedback = createOptionFeedback(options);
Error in fsolve (line 157)
[options, optionFeedback] =
prepareOptionsForSolver(options, 'fsolve');

R2018b

### Community Treasure Hunt

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

Start Hunting!