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 ExchangeSparse 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