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

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.

Related

'solve' syntax in MATLAB for symbolic nonlinear matrix equation

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?

Integrate differential equations in Matlab

I am facing a problem in which I have to solve a system of equations:
\partial A \delta x = f(A) g(B)
\partial B \delta y = h(A) k(B)
in which f,g,h and k are some functions of A or B, and I have some initial conditions A(x=0) = a, B (y=0) = b. All previous variables are scalars.
I have solved this by making a little step in one variable and then integrating the other other equation for the whole range of the other variable (like an ode routine), then another step in the former variable and so on.
Do you have another idea more efficient? Is it possible to put one ode call running inside another call? Or perhaps there is something more elegant like combining both independent variables x and y, integrating a vector function and then undoing the change? I have the feeling that this could be done in some way.
Many thanks!
This looks to me like a partial differential equation system.
You can solve it with pdepe (here is the documentation) or you can discretize one dimension, let's say x, in Np points and have one y-equation on each point. You would complicate your system from 2 equations to Np, but turn it from PDE to ODE and therefore solvable with Matlab's ODEs.

Solving systems of nonlinear equations

Help. I am trying to solve this system of nonlinear equations in MATLAB for a homework assignment. I have tried wolfram alpha and this online equation solver, and neither of them work.
I have tried my graphing calculator and it keeps saying non algebraic variable or expression.
These are my two equations in two unknowns:
.75*(1100)= x*10^(6.82485-943.453/(T+239.711))
25*1100=(1-x)*10^(6.88555-1175.817/(T+224.887)
I don't quite understand how to use MATLAB to solve this system. Please help.
You want the function fsolve in Matlab. Define a function myfun that returns [0,0] at the solution, then run fsolve(myfun,x0). x0 is a guess for the solution.
Define myfun:
function F = myfun(x)
F = [<put modified eqt1 here>;
<put modified eqt2 here>;];
Save it. Then solve:
x0 = [1,1];
options = optimoptions('fsolve','Display','iter');
[x,fval] = fsolve(#myfun,x0,options) % Call solver

ODE System, IVP with differential initial condition

I am trying to model a system of three differential equations. This is a droplet model, parametrized vs the arc length, s.
The equations are:
dx/ds=cos(theta)
dz/ds=sin(theta)
(theta)/ds=2*b+c*z-sin(theta)/x
The initial conditions are that x,z, and theta are all 0 at s=0. To avoid the singularity on d(theta)/ds, I also have the condition that, at s=0, d(theta)/ds=b. I have already written this code:
[s,x]=ode23(#(s,x)drpivp(s,x,p),sspan,x0);
%where p contains two parameters and x0 contains initial angle theta, x, z values.
%droplet ODE function:
function drpivp = drpivp(s,x,p);
%x(1)=theta
%x(2)=x
%x(3)=z
%b is curvature at apex
%c is capillarity constant
b=p(1);
c=p(2);
drpivp=[2/p(1)+p(2)*x(3)-sin(x(1))/x(2); cos(x(1)); sin(x(1))];
Which yields a solution that spirals out. Instead of creating one droplet profile, it creates many. Of course, here I have not initialized the equation properly, because I am not certain how to use a different equation for theta at s=0.
So the question is: How do I include the initial condition that d(theta)/ds=b instead of it's usual at s=0? Is this possible using the built-in solvers on matlab?
Thanks.
There are several ways of doing this, the easiest is to simply add an if statement into your equation:
function drpivp = drpivp(s,x,p);
%x(1)=theta
%x(2)=x
%x(3)=z
%b is curvature at apex
%c is capillarity constant
b=p(1);
c=p(2);
if (s == 0)
drpivp=[b; cos(x(1)); sin(x(1))];
else
drpivp=[2/p(1)+p(2)*x(3)-sin(x(1))/x(2); cos(x(1)); sin(x(1))];
end

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