equation solution with matrices

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.

답변 (2개)

John D'Errico
John D'Errico 2016년 10월 22일

0 개 추천

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.
Jan
Jan 2016년 10월 22일
편집: Jan 2016년 10월 22일

0 개 추천

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?

카테고리

도움말 센터File Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

질문:

2016년 10월 22일

편집:

Jan
2016년 10월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by