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
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
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
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!