solving nonlinear equations including max function - matlab

I want to solve this system of equations using MATLAB:
I solved the second equation and put it in the first one. Then I tried this:
syms v_star
eqn = max((1.8+0.81*v_star), (-1+0.9*v_star)) == v_star;
solx = solve(eqn,v_star)
And I get this error:
Error using symengine
Input arguments must be convertible to floating-point numbers.
How can I solve this system of equations?

Related

System of non linear equations with parameters

I'm triying to solve a system of non linear equations in matlab. I am trying to use fsolve to solve the same system but with different parameters.
k1=0.01;
k2=0.05;
k3=10;
k4=100;
Ca0=1;
f2=#(C,tau) [Ca0-C(1)-tau*(k1*C(1)-k2*C(2)+k4*C(1).^2);C(2)-tau*(k1*C(1)-k2*C(2)-k3*C(2))];
t = linspace(0,1);
for i = 1:length(t)
options=optimset('display','off');
solution(i) = fsolve(f2,[2 0],options,t(i));
end
Then I need to plot the solution, but I keep getting Subscripted assignment dimension mismatch.

Using MATLAB's solve function to find solution to system of equations

I am having trouble solving a system of equations. I have three equations with a known solution and three unknowns in each equation. However, when I use the solve function in MATLAB, it returns with the error that I have six equations and three variables.
A snippet of my code:
syms V0 T0 X0
A=(g*X0/(2*V0^2*cos(T0)^2)-tan(T0))==a;
B=(tan(T0)-g*X0/(V0^2*cos(T0)^2))==b;
C=(-g/(2*V0^2*cos(T0)^2))==c;
soln=solve([A,B,C],[V0,T0,X0]);
I have already calculated scalar values for a, b, and c. g is a constant.
I am not sure why it is returning that I have six equations.
V0^2 means its a quadratic equation. You could solve for V0^2 as a variable. Set V0^2 = J0 and solve for J0 instead.
soln=solve([A,B,C],[J0,T0,X0]);
Then its three linear equations with three variables.
Once you get value of J0, then you need to solve for V0^2 = J0.

solving a quadratic equation with matrices in matlab

I'm trying to numerically find the solution to X^2+X+C=0 where C is the matrix C=[-6,-5;0,-6] and 0=[0,0;0,0], a quadratic equation where the variable is 2x2 matrix.
So I wrote the following matlab commands
C=[-6,-5;0,-6]
[X1,F,e_flag]=fsolve('X^2+X+C',[1,1;1,1])
where [1,1;1,1] is our initial estimate, or X0.
I'm getting the following errors
"Error using inlineeval (line 15)
Error in inline expression ==> X^2+X+C
Undefined function or variable 'X'.
Error in inline/feval (line 34)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr,
INLINE_OBJ_.expr);
Error in fsolve (line 218)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE
cannot continue."
How do I use fsolve to solve these kind of problems?
I don't think fsolve can be used with a string representation of your equation.
You should rather pass a function handle to the solver like this:
C = [-6,-5;0,-6];
[X1,F,e_flag] = fsolve(#(X) X^2+X+C,[1,1;1,1]);
It also depends on what you mean by: X^2. In Matlab this means the matrix product X*X. If you want entry-wise squaring you should use X.^2, in which case you will have four independent quadratic equations, which you could solve independently.

Partial derivative with Matlab Symbolic Toolbox for Lagrangian equations of motion

I'm trying to derive Lagrangian equations of motion in Matlab using the symbolic toolbox. This involves partial derivatives of a function and your coordinates, but matlab seems to not accept this.
So I would do this in Matlab:
syms t x(t) % t: time, x(t) position dependent on time
m = sym('m'); % mass, a constant parameter
T = m/2*diff(x,t)^2; % kinetic energy
dTdx = diff(T,x);
ddTdxDotdt = diff( diff(T,diff(x,t)), t);
But as soon as I try to differentiate anything in x (or diff(x,t)), Matlab complains:
Error using mupadmex
Error in MuPAD command: The variable is invalid. [stdlib::diff]
Error in sym/diff (line 44)
R = mupadmex('symobj::diff', S.s, x.s, int2str(n));
Does anyone know the proper way of handling this?
Matlab ought to be able to do this as you have it written, but I think that it doesn't like taking derivatives with respect to a symfun. Type whos in the command window and you'll see that x is listed as a symfun while t is just a sym. The help for diff kind of indicates this limitation. It won't event try to take the derivative of a constant with respect to x(t): diff(1,x) "complains" just the same. Unless newer versions of Matlab fix this (I'm on R2012b) I think you only option may be to come up with a scheme using two instances of x.

How to solve complex system of equations using matlab?

I have to analyze 802.11 saturation throughput using matlab, and here is my problem. I'm trying to solve parametric equations below (parameters are m,W,a) using solve function and i get
Warning: Explicit solution could not be found
How could I solve above equations using matlab?
I guess you were trying to find an analytical solution for tau and p using symbolic math. Unless you're really lucky with your parameters (e.g. m=1), there won't be an analytical solution.
If you're interested in numerical values for tau and p, I suggest you manually substitue p in the first equation, and then solve an equation of the form tau-bigFraction=0 using, e.g. fzero.
Here's how you'd use fzero to solve a simple equation kx=exp(-x), with k being a parameter.
k = 5; %# set a value for k
x = fzero(#(x)k*x-exp(-x),0); %# initial guess: x=0