Hi, I'm trying to square an array, but it won't work for some reason, and I cannot figure out why. I'm sure I'm probably overlooking something big though.
x=[a:10:b];
y=x.^2;
gz=-0.2794*(p)*(r^3)*z/((y+z^2)^(3/2))
It gives me multiple errors whenever I try to run this code through, even though I coded all of the variables, it doesn't like trying to square them.

댓글 수: 1

Torsten
Torsten 2022년 8월 29일
편집: Torsten 2022년 8월 29일
Please include the full code and write exactly what does not work.
In gz, you will of course have to use .^, .* and ./ instead of ^, * and /
x = 1:10;
y = x.^2
y = 1×10
1 4 9 16 25 36 49 64 81 100

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2022년 8월 29일
편집: Image Analyst 2022년 8월 29일

0 개 추천

This works fine for me
% Define parameters
a = 10;
b = 40;
x=[a:10:b]
x = 1×4
10 20 30 40
y=x.^2
y = 1×4
100 400 900 1600
% Define parameters
p = 2;
r = 3;
z = 6;
gz=-0.2794*(p)*(r^3)*z ./ ((y+z.^2) .^ (3/2))
gz = 1×4
-0.0571 -0.0099 -0.0032 -0.0014
If you have any more questions, then attach your actual error message (ALL the red text) and data (actual parameters) and code to read it in with the paperclip icon after you read this:
Nisarg
Nisarg 2024년 5월 8일

0 개 추천

class_intervals = [10, 20, 30, 40, 50];
frequencies = [5, 8, 12, 10, 6];
n = sum(frequencies)
mean = sum(class_intervals .* frequencies)/n
y = sum(frequencies.*((class_intervals - mean).^2))
std = sqrt(y/n)

카테고리

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

태그

질문:

2022년 8월 29일

답변:

2024년 5월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by