Matrix equations in Matlab [closed] - matlab

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am doing an introduction course in MATLAB (I am a beginner) and I'm having trouble solving an issue regarding an equation of matrices.
The equation is
AX = C - BX
I want to solve for the matrix X. No matter how I have tried to solve it I come up either empty handed or with some sort of a syntax error. I think I am missing something fundamental.
Any help on the subject is very much appreciated.

For this equation to be consistent, A and B must have the same size. Therefore, you can re-write your equation as:
(A+B)X = C
This can be solved in MATLAB with:
X = (A+B)\C
Note that this will always find a solution, regardless of the size of A+B:
If A+B is square, you'll find "the" solution.
if A+B is over/underdetermined, it will return a least-squares approximation to X.
It's up to you to decide whether this is desirable or not.
In case C is zero, you might want to use null (or look at svd).

Related

fmincon with nonzero inequalities constraint [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I want to solve a minimization problem in MATLAB.
fmincon():
x = fmincon(fun,x0,Aeq,beq, nonlcon) subjects to the nonlinear inequalities c(x) defined in nonlcon such that c(x) < 0
Is it possible to change c(x) < 0 to c(x) ≤ 0 and use fmincon() function? Does it have any effect on my obtained results? I tried fmincon and obtained the reasonable results but I do not know the effect of this change in my results? which function do you suggest to use in MATLAB for this problem?
It should be noted that, strictly speaking, the constraint c(x) < 0 is a subset of c(x)<=0, so your result of optimization should be a solution with relaxed condition when with c(x)<=0.
Considering the numeric calculation by MATLAB, the impact might be tiny since you also have calculation precision issues, so no need to worry about it.

Generate a random variable with an exponential distribution [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In Matlab using the rand routine, how should I write the code to generate 500 samples from an exponential distribution, whose pdf is:
(1/mu)*exp(-x/mu); x>=0
Assuming you really have to do it using the rand function: exploit the property that the minus logarithm of a normalized uniform RV is a normalized exponential RV:
samples = -mu*log(rand(1,500));
Use random function.
For example to create a 4*6 matrix with mu=1.3 with an exponential distribution use:
random('Exponential',1.3,4,6)
or
random('exp',1.3,4,6)
If you have the Statistic toolbox you can simply use exprnd much like you use rand:
r = exprnd(mu);
where the size of r will be the size of the mean, mu, or
r = exprnd(mu,m,n);
where mu is a scalar mean, and m and n are the size of your desired output. If you type edit exprnd, you'll see that the code is virtually identical to that kindly provided by #LuisMendo. You might find the other functions related to the exponential distribution helpful to, such as exppdf and expcdf. These are simple as well and implement basic equation that you can find in your textbook or on Wikipedia.

generate eigen images of an image matlab [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am new to image processing and am trying to learn few concepts by practically implementing certain functions. I heard about creating eigen images of an image, so tried to implement the same, to actually know what they are and what properties they alter.
Thus I obtained the eigen vectors using the eig function in matlab. How can I display these eigen images using the vector? Please forgive me if the question is wrong or rudimentary. Your help is much appreciated.
Assuming you have several images of size r x c, then taken the steps described on wikipedia, you should now have eigenvectors ev1, ev2 ... of length r x c.
If this is the case, it should be fairly easy to turn these into images again:
myImage1 = reshape(ev1,r,c);
Check whether r and c are in the right order and whether you need to transpose, but this is basically it.
For showing them you may want to look into surf or image.

How to find the solution space (x,y,z) for a function f(x,y,z)=0 in MATLAB [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a function, dependant on a vector k=(x,y,z) and a function f(x,y,z)=0, I would like to find the solution space for (x,y,z).
Can this even be done analytically in matlab? I imagine it can be done numerically because my initial thought was to plot the surface created by this function, however this is of no use to me as I have 9 other constants in my equation with no numerical value assigned to them. Many thanks in advance for any help.
EDIT: This is for a polynomial degree 4.
There are no generic, analytical solvers for given function f(x,y,z) neither in matlab, nor in any other language. If such solution would exist, the Riemann hypothesis (and dozens others) would be solved ;)
For simple problems you could use symbolic math toolbox and a solve function:
http://www.mathworks.com/help/symbolic/solve.html
And obbiously there are numerical solvers, which you can use like vpasolve and others
http://www.mathworks.com/help/symbolic/vpasolve.html

Image processing: Minimizing laplacian norm with boundary conditions [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm trying to minimize this function (by A):
argmin_A (||L(A)||^2 + a||A-B||^2*)
where:
A is a MxN image L is the Laplacian Operator
||.|| is the usual norm (Frobrenius)
a is a weight parameter
B is a matrix of size (M+2*k)xN
where k is an integer parameter.
(*) indicates that we just consider the pixels in the boundary (we want to preserve in A the pixels in the boundary of B).
Maybe the problem has a trivial solution, but I'm absolutely blocked.
If you need more details, it's (4) equation in this paper.
I will be very grateful for any help provided.
Without looking carefully at that paper, gridfit does essentially that, although it does not employ the boundary conditions you ask for. You could certainly write what you want however, or you could simply apply a weight to the boundary points. This is not a difficult problem, but in order to solve it efficiently, you would want to employ the sparse matrix capabilities of MATLAB.