Solving an equation using Matlab - math

S=solve(strcat('a*gamma(1+(1/b))=',int2str(m)),strcat('a*a*gamma(1+(2/b))=',int2str(c)));
Values of variables m and c are known. How can one solve for a and b?

I guess a and b are arbitrary constants. You can assign it as syms. If you really need to solve for a and b, use two equations two unknowns or the solve() function in matlab.

Try the optimization toolkit if you have it:
f = #(a,b) (a(1)*gamma(1+(1/a(2))) - b(1))^2 + (a(1)^2*gamma(1+(2/a(2)))-b(2))^2;
X = fminsearch(#(a) f(a,b),[1;1])

Related

How can I write this line of code in MATLAB (currently R)?

How can I write this line of code in MATLAB (currently R)?
vcov_beta_hat <- c(sigma2_hat) * solve(t(X) %*% X)
My attempt is,
vcov_beta_hat = [sigma2_hat.*((X'*X))];
However I am struggling on what the 'c' is doing in the r code?
Whilst the above answer addresses that the solve is the something missing in your matlab code, solve can mean a number of different things in R,
If there is no comma in the equation its not solving anything and is actually taking the inverse,
Inverse of A, MATLAB: inv(A) R: solve(A)
Therefore, vcov_beta_hat = [sigma2_hat.*inv((X'*X))];
The c(a,b,c) denote a vector in R. In Matlab, you would write
vec = [a b c];
Also, you need to find the equivalent of the R-solve() function. So far, your matlab code just mutliplies X' with X and does not solve the system of equations.
linsolve should be a good starting point.

Solve Underdetermined System of Equations for Sparse Solution

A, C are m x n rectangular matrix.
B is a n x n square matrix.
B is not symmetric.
B, C are known
AB = C.
B is singular.
I could use the moore-penrose inverse of B to get A = CB+.
But that seems to make A have many non-zero elements.
If I want an A (among all possible solutions) that is quite sparse, what solvers can I try?
Should I use BDCSVD, as in here?
Thanks.
Under-determined systems usually have infinite number of solutions. Unless you impose some additional conditions (restrictions), in form of additional equation(s), you won't obtain a single numerical solution.

Quadratic Objective with Quadratic Constraints in R: Rsolnp?

I am trying to minimize a quadratic objective with quadratic constraints, is Rolnp the way to go? I have been reading the documentation and it seems like all the examples use equations instead of vector manipulation. All of my parameters are vectors and matrices and they can be quite large. Here is my problem:
X<-([Cf]+[H])%*%[A]
Y<-([Cf]+[H]-[R])%*%[B]
I want to find H that minimizes Y%*%Dmat%*%t(Y) for a given value of X%*%Dmat%*%t(X)
Cf, R, A, Dmat and B are matrices of constants.
The values for H sohould be between 0 and 1.
Is it possible to use Rsolnp to find the vector H even though the input functions will all return other vectors?
I ended up using AUGLAG and COBYLA to solve this problem.

VBA How to solve two equations with two unknowns

I am trying to calculate point on a line.
I got the points of the edges and one distance between one edge to the point I want to find (which is B).
A(2,4)
B(x,y)
C(4,32)
The distance between A to B is 5.
How can I calculate Bx and By? using the following equations:
d = Math.Sqr((Bx-Ax)^2 + (By-Ay)^2)
d = Math.Sqr((Cx-Bx)^2 + (Cy-By)^2)
and than compare the equations above.
Here is the equations with the points placed:
5 = Math.Sqr((Bx-2)^2 + (By-4)^2)
23.0713366 = Math.Sqr((4-Bx)^2 + (32-By)^2)
or
Math.Sqr((Bx-2)^2 + (By-4)^2) - 5 = Math.Sqr((4-Bx)^2 + (32-By)^2) - 23.0713377
How can I solve this using VBA?
Thank you!
I won't solve your equations above because they are an unnecessarily complex way to state the problem (and the existence of a solution is questionable in the presence of rounding), but all the points on the line A=(Ax,Ay) to C=(Cx,Cy) can be described as B=(Ax,Ay) + t*(Cx-Ax,Cy-Ay) with t between 0 and 1.
The distance between B and A is then given by d=t*Sqrt((Cx-Ax)^2+(Cy-Ay)^2), which you can invert to get the proper t for a given d - t=d/Sqrt((Cx-Ax)^2+(Cy-Ay)^2)
In your case, B(t) = (2,4) + t*(2,28), t=5/Sqrt(2^2+28^2) ~ 0.178 -> B ~ (2,4) + 0.178 * (2,28) ~ (2.356, 8.987).
VBA has no Symbolic Language capability. To solve this problem, there are different approach :
Transform the equations to isolate one of the unknowns, most likely to use substitution, and compute it (I recommend this for your problem.)
Transform your functions and derive them to use Newton's methods (don't do this, it's overkill.)
Use a "brute force" convergence methods : Fix a min/max for each variable and use bisection methods to find what you want (I don't recommend this because you'll most likely "fall" into a local minimum/maximum in your case.)
So basically, I'd say you go with the first way. It requires 15mins of tinkering with mathematical equations, then you're set to go.

troubles with integration on matlab

I'd like some help please I really need to solve this problem.
Well before anything thank you for your time...
My problem: I have a matrix (826x826 double) and I want to integrate this matrix with respect to a vector of (826x1 double) I don't have the functions of any of this. Is there a command or an algorithm to take the integral of a matrix with respect to a vector? Please I really need help, I'm such a newbie at matlab.
Sincerely.
George
If it's a constant matrix A integrated with respect to vector x, your answer in simply Ax + c where c is some constant vector. If A is a function of x, you will need to specify exactly what it is. Another case is when both A and x are functions of t. There is no one simple answer and no computer program would do it in most cases. There are books written in this stuff. It's not an easy task.
If I understand correctly, you have a matrix Y (size mxn) and a vector X (size mx1) where Y(i, j) = f_j(X(i)) for some unknown function f_j. To approximate the integral of each column over X you could use the trapz function of Matlab which uses the trapezoidal method.
A = trapz(X, Y);
This will integrate Y along its columns using the vector X. If you wanted to integrate along rows you can call the trapz function with an added argument of dim=2. Of course, the dimensions of X and Y must be compatible in either case.

Resources