How to find the chi value with changing inputs

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 Comments

Include data (.mat file) and show a formula of y(i).
Obviously, i should be a whole number in order to be index, so the "for" statement is incorrect.
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?
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.

Sign in to comment.

Answers (1)

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

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Asked:

on 26 Oct 2023

Answered:

on 30 Oct 2023

Community Treasure Hunt

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

Start Hunting!