I have a system of 8 equations and 8 unknowns. There is nothing numerical in these set of equations. All there is in the equations is parameters; 8 of these parameters are my unknown variables (hereafter, unknown variables), which I'm solving for, and there are a bunch of other parameters, that are NOT unknown values, such as alpha, beta, gamma (hereafter, parameters).
I need to solve the system of equations, such that I get the 8 unknown variables in terms of parameters.
I used fsolve([equations],[variables]) in Maple. However, it returns an error that says tau, alpha, beta, ... are in the equations and are not solved for. How can I make Maple to understand that these are not variables that I like to solve for, but they are just parameters that the rest of unknown variables should be solved in terms of?
Here is an example of one of my equations:
e1 := (L__af+L__mf)/(1-tau) = `A__a,star`*L__ah^(1-alpha)*`L__ah,star`^alpha/A__a+`A__m,star`*L__mh^(1-alpha)*`L__mh,star`^alpha/A__m
in which all L's are unknown variables and anything else should be treated as a known parameter.
fsolve is for doing numerical solutions as opposed to symbolic. For a numerical solution, your values for the known variables have to have a numerical value assigned to them. If you want a symbolic solution, try solve({equations},{variables}). If it can't find a solution, then try fsolve, but with specific values for those variables.
Related
im using Matlab to trying to solve 2 equations with 2 variables.
I define the 2 functions, f2(n_1,n_2),f3(n_1,n_2) which both depend on f1(n_1,n_2), then I defined the vectorised function G(n_1,n_2) which contain both of them.
Later I defined a the desired stating point, and tried to solve. but when running the code it raise an error which I'm not fully understand.
the above mentioned is displayed in the code below:
the code:
clear, close all; clc
%Const
N0=25;
G1=1;G2=1;
a1=6;a2=3;
k1=1;k2=4;
%main
syms n_1 n_2
X_0=[-5;5];
f1=N0-a1.*n_1-a2.*n_2;
f2=f1.*G1.*n_1-k1.*n_1;
f3=f1.*G2.*n_2-k2.*n_2;
G=#(n_1,n_2) [f2;f3];
s = fsolve(G,X_0);
the error:
Error using fsolve (line 269)
FSOLVE requires all values returned by functions to be of data type double.
Error in Ex1_Q3_DavidS (line 37)
s = fsolve(G,X_0);
thanks
fsolve is a function that uses numerical methods to find the root of a numerical function.
A numerical function is, for example f=#(x)x^2=2;. In MATLAB, you can evaluate f() at any number and it will return a number, but there is no higher order mathematical abstraction to it. This is however the fastest way to do maths in a computer, as it is not a higher intelligence, just a glorified calculator.
Some people however, want to give higher intelligence to computers and coded very complex symbolic toolboxes that with sets of rules try to teach computers to think semi-like humans and solve symbolic equations, as you do in paper. To solve those equations a function called solve is introduced in MATLAB.
You are doing symbolic math, but using the numeric solver. It does not work, just use the symbolic solver for symbolic math.
I have a symbolic matrix that depends on a complex parameter q. Let the matrix be A(q) and b a column vector. I would like to simultaneously solve the equations
A*b==0; b'*b==1;
using the solve command (preferably the numerical variant vpasolve). The variables to be found are both b and q. I am not quite sure about the syntax on how to do this and would appreciate any help on it. My main problem is that the equation is partially given in matrix form and the searched variable is a vector.
Do I have to resort to fsolve to achieve this? Or is there a way without defining a function?
Let's say that I want to solve a system of N equations with N unknown variables. Assume the equation is of the following general form (I have simplified it greatly, and we can pretend each line is equal to zero).
x1 - const(1)
x2 - const(2)
x3 - const(3)
...
xN - const(N)
where x1, x2, ..., xN are my variables, and const is a vector of length N of constants determined earlier in the code. I do not know in advance (i.e. cannot hard-code) how many equations and variables there are, but I still wish to write and solve the system in a general way.
In MATLAB, my current solution is to do the following, where n_vars is the number of variables, which my program determines earlier on.
sym_vars = sym('x',[1 n_vars]);
for i = 1:n_vars
eqn(i) = sym_vars(i)-const(i);
end
This builds the system of equations. eqn, that I showed above. All of the numerical solvers (e.g. fsolve, lsqnonlin, ode45) that I plan to use require the system of equations to be defined as a function handle or as a separate function entirely. I can convert the symbolic expression to a function handle via matlabFunction or, if dealing with ODEs, via odeFunction to address this.
However, there are two main issues with this approach that I want to resolve. The first is that I do not want to have to make symbolic variables and rely on the symbolic toolbox if I am only performing numerical computations. The second is that if I am solving ODEs, the variables actually have to be x1(t), x2(t), x3(t), ..., xN(t) for odeFunction to work properly. However, using the same logic as my sym approach above to make these variables in a general way leads to a warning because character vectors that aren't valid variable names will not be allowed in future releases.
How can I write a system of equations using function handles instead of symbolic variables (or an equivalent solution)? Surely there must be a way to write a system of equations without doing so manually.
Use a vector function like
N=5;
const=1:5;
fsolve(#(x)x-const,zeros(1,N))
the result is:
1.0000 2.0000 3.0000 4.0000 5.0000
I am trying to use matlab's fsolve to solve a system of 4 nonlinear equations. I'm solving the system for each point in a grid of parameters by looping through each point and calling the fsolve function.
My problem is that I need to give some of these parameters as input to fsolve. These inputs should be treated as constants for each separate solving of the system.
Can anyone help me?
you can just do:
result = fsolve(#(x) eqns(a,b,c,d),guess)
and in addition make the function eqns() with your equation set.
I want to solve a system of non-linear equations in matlab such that the solutions are positive. Can I specify in matlab that I want positive solutions for unknown variables? How?
Yes, you can define the variables with syms like:
syms x y positive
and those variables are constained to be positive. See fsolve for how to find the solution after you have define the constraints on variables.