How to find the chi value with changing inputs

1 次查看(过去 30 天)
I have physic project where I have to find the maximum value between a set of data points. My prof told me I have to use the chi squared function over a range of points. I have tried to create a code but I am struggling to get it to work. data is a 37x2 double matrix. I want to sum all of the values of the function by changing the value of vi and theta everytime but I keep getting error stating that my matrix must be square to be squared. Im not sure what to do, please any suggestions would be appriecated.
Vi = data(:,2);
Vo = 33.659;
theta = data(:,1);
for i = 120:0.5:130
syms x;
y(i) = symsum((Vi-Vo*cos(theta-i)^2)^2/0.1^2,[1,36]);
end
display(y)
  3 个评论
Dyuman Joshi
Dyuman Joshi 2023-10-26
编辑:Dyuman Joshi 2023-10-26
It's not clear to me what the objective is.
You are using symsum(), but there is no symbolic variable in the expression for which to sum through different values. Although you have defined "x" as a symbolic variable, but haven't used it.
Could you provide the mathematical formulation of the problem?
Walter Roberson
Walter Roberson 2023-10-26
theta is a column vector cos(theta-i) is a column vector. The ^ operation requires that the base array must be a square array. You need the .^ operator rather than the ^ operator.
This is not your only problem but it will solve the immediate problem.

请先登录,再进行评论。

回答(1 个)

SAI SRUJAN
SAI SRUJAN 2023-10-30
Hi Elise McGoldrick,
I understand that you are facing an issue in using the chi squared function over a range of points.
The code is erroring out due to the incorrect use of "^" operator and improper syntax of "symsum" MATLAB function. Although you have defined "x" as a symbolic variable, but haven't used it in the symsum function. The operator "^" expects the Base matrix to be a square matrix whereas "cos(theta-i)" is a column vector.
You can follow the given example to proceed further.
Vi = data(:,2);
Vo = 33.659;
theta = data(:,1);
y = zeros(size(120:0.5:130)); % Preallocate the y vector for efficiency
for i = 1:numel(y)
sum_squared_diff = sum((Vi - Vo*cos(theta - (120 + (i-1)*0.5)).^2).^2);
y(i) = sum_squared_diff / (0.1^2);
end
display(y)
For a comprehensive understanding of the "symsum" function in MATLAB, please refer to the following documentation

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by