How can i bring this equation into matlab?
2 次查看(过去 30 天)
显示 更早的评论
Hi, I want to make a equation solver with matlab.
what i want to make is attatched down below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/601870/image.png)
here, i have a thousand of data point with alpha and temperature.
also i have A, E, and R value.
here, what i tried is like this.
g_alpha = A/beta*cumtrapz(exp(-E./(R*T(2:length(T),:))));
and
n = 2;
G_alpha = [];
while n < 1000;
g_alpha = A/beta*int(exp(-E./(R*T(n+1,:))),[T(2,:) T(n+1,:)]);
G_alpha = [G_alpha; g_alpha];
n = n + 1;
end
but both of these aren't work well.
do i miss something?
can anyone help me to make this completely?
1 个评论
Walter Roberson
2021-4-30
The equation does not appear to involve alpha on the right side, so the integral can be expressed as
T*exp(-E/(R*T)) + (E*ei(-E/(R*T)))/R
provided that E and R are positive.
I am not clear on what the task is? You seem to have a vector of T values but what are you trying to solve?
回答(1 个)
Nipun
2024-5-22
Hi Kihoon
I understand that you are trying to create a MATLAB solver for the integral equation involving g(α) using provided data points for α and temperature, along with constants A, E, and R.
Here is the correct MATLAB code to compute the integral:
% Given data and constants
alpha = ... % Your data points for alpha
T = ... % Your data points for temperature
A = ... % Given constant A
E = ... % Given constant E
R = ... % Given constant R
beta = ... % Given constant beta
% Number of data points
num_points = length(T);
% Initialize the result array
g_alpha = zeros(num_points, 1);
% Loop to calculate g(alpha) using cumulative trapezoidal integration
for i = 1:num_points
% Define the integrand function
integrand = @(t) exp(-E ./ (R * t));
% Calculate the integral from 0 to T(i)
integral_value = integral(integrand, 0, T(i));
% Calculate g(alpha)
g_alpha(i) = (A / beta) * integral_value;
end
% Display the result
disp(g_alpha);
Make sure to replace the placeholders for alpha, T, A, E, R, and beta with your actual data and constants.
Explanation:
- The integral function is used to compute the definite integral of the specified integrand function from 0 to 𝑇(𝑖)T(i).
- The integrand function is defined as an anonymous function @(t) exp(-E ./ (R * t)).
- The loop iterates over all temperature data points, computes the integral for each, and then calculates 𝑔(𝛼)g(α) for each point.
Refer to the following MathWorks documentation for more information on "integral" function: https://in.mathworks.com/help/matlab/ref/integral.html
Hope this helps.
Regards,
Nipun
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!