Error while contour plotting an integral.

3 次查看(过去 30 天)
I am trying to plot this temperature equation like a simulation. The temperature should be a function of x and z with t as varying time step. We are getting this error: Input arguments must be numeric or objects which can be converted to double.
I have written the following code. Can someone please help in this?
% Material Properties
P= 50;
eta= 0.3;
rho=4429;
D=2.89*10^(-6);
Cp=553;
T0=300;
v=0.1;
%function% Define the range of x and z values
x_range = linspace(-10, 10, 100); % Adjust the range and number of points as needed
z_range = linspace(-10, 10, 100); % Adjust the range and number of points as needed
fun = exp(-((z - z1).^2 + (t/10 - t1/10 - x + x1).^2)./((6823819567746637*t)./590295810358705651712 - (6823819567746637*t1)./590295810358705651712))./(t - t1).^(3/2);
% Create a grid of x and z values
[X, Z] = meshgrid(x_range, z_range);
% Define the number of time steps
num_time_steps = 10; % Adjust as needed
% Initialize a cell array to store the integral results for each time step
integral_results = cell(num_time_steps, 1);
% Calculate the integral result for each time step
for t_step = 1:num_time_steps
t = t_step * 0.1; % Adjust the time step as needed
% Initialize a matrix for this time step
integral_result = zeros(length(x_range), length(z_range));
for x_index = 1:length(x_range)
for z_index = 1:length(z_range)
x = x_range(x_index);
z = z_range(z_index);
% Numerical integration using quad
fun_numeric = @(t1) double(subs(fun, {x, z, t, x1, z1}, {x, z, t, x, z}));
integral_result(x_index, z_index) = integral(fun_numeric, 0, t);
end
end
% Store the result in the cell array
integral_results{t_step} = integral_result;
end
% Create contour plots for each time step
for t_step = 1:num_time_steps
t = t_step * 0.1; % Adjust the time step as needed
figure;
contourf(X, Z, integral_results{t_step}, 20); % Adjust the number of contour levels as needed
colorbar;
xlabel('x');
ylabel('z');
title(['Contour Plot at t = ' num2str(t)]);
end
  5 个评论
Star Strider
Star Strider 2023-8-20
Did you use my revision of your code, or something else?
If you changed it, please post the new code.
When I ran it, the code I posted runs without error, although it takes forever, so I stopped it before it finished.
Pooja Kumari
Pooja Kumari 2023-8-28
Can you tell what is y and y' in the image attached above?

请先登录,再进行评论。

回答(1 个)

Pooja Kumari
Pooja Kumari 2023-8-29
编辑:Pooja Kumari 2023-8-29
Dear AD,
I understand that you are facing issue with contour plot of this integral function provided in the temperature function below:
These are some troubleshooting steps which you can follow:
Here is a sample code for reference:
syms x z t x1 z1 t1;
Here is a sample code for reference:
q = integral(@(t1) fun(t1,5),0,2);
You can refer to the below documentation for more information on contour plot:
Regards,
Pooja Kumari

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by