How to find the chi value with changing inputs
1 view (last 30 days)
Show older comments
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
Dyuman Joshi
on 26 Oct 2023
Edited: Dyuman Joshi
on 26 Oct 2023
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
on 26 Oct 2023
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.
Answers (1)
SAI SRUJAN
on 30 Oct 2023
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
0 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!