equation solution with matrices
Show older comments
I have this equation;
z=(log(x.^(-2) .* y.^3) .* 10^3 .* y.^abs(x)) ./ (factorial(4) .* 1.5 .* 2.8 ./ 3.16 ) + (2.^(1/3) .* 5 + 6 .* 2.^(-2) ./ 3.^2 .* 4 .*log(8./sqrt(x.*y)) ) ./ (exp(0.2 .* x) .* sin(y.^(-2)).^2 .* abs(cos(x-y)).^(1/3) .* 0.25)
and my x and y values are respectively like that; x=[4 2 1 3] y=[2 1 0.5 1]
how will i solve this z equation with for loop? and get z in matrix form again?
thanks guys.
Answers (2)
John D'Errico
on 22 Oct 2016
Why do you need a loop of any kind? Did you try just evaluating that expression as is?
x = [4 2 1 3];
y = [2 1 0.5 1];
z=(log(x.^(-2) .* y.^3) .* 10^3 .* y.^abs(x)) ./ (factorial(4) .* 1.5 .* 2.8 ./ 3.16 ) + (2.^(1/3) .* 5 + 6 .* 2.^(-2) ./ 3.^2 .* 4 .*log(8./sqrt(x.*y)) ) ./ (exp(0.2 .* x) .* sin(y.^(-2)).^2 .* abs(cos(x-y)).^(1/3) .* 0.25);
So, did you try it? Why not?
The only thing that I see that might be problematic are things like:
y.^abs(x)
You need to be careful if the base can ever be negative, and the exponent a non-integer. You need to remember that a fractional power of a negative number has multiple solutions, some of which are complex.
x = [4 2 1 3];
y = [2 1 0.5 1];
z = zeros(length(x), length(y));
for ix = 1:length(x)
for iy = 1:length(y)
z = ...
end
end
Now insert "x(ix)" and "y(iy)" inside the formula.
It looks simple to create two loops, when you know already, that you want to use loops, doesn't it?
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!