How i can run this code with simple boundary conditions given in code

37 次查看(过去 30 天)
fun_u
J1=0.1;J2=0.1;J3=0.1;J4=0.1;J5=0.1;J6=0.1;
S = 0.0001;
GC = 0.1;
Gr = 0.1;
Ha2 = 0.1;
a=1;
m = 2;
G = 1;
t = 0.1;
phi=0.1;
u1 = exp(-t) - 1;
term1 = (-33 / J1) * (1 - exp_t - 2 / 3 * S);
term2 = 2 * GC * J3 + 2 * Gr * J2;
term3 = (2 * J4 * Ha2) / (1 + m^2);
term4 = 3 * GC * exp_t + 6 * exp_t / ((1 - phi)^2.5);
term5 = 2 * GC * J3 * exp_t + 2 * Gr * J2 * exp_t;
u2 = exp(-t)*(term1 + term2 - term3 - term4 - term5 + term3 * (exp_t - m + m * exp_t)) / (6 * a);
u = u1 * y + u2 * y^2;
% b.c
u(0)=0; u(1)=0;
axis([0 1 0 0]);
end

回答(1 个)

Shivam
Shivam 2024-9-10,5:01
Hi Sharqa,
I see that you are having difficulty in executing the provided code snippet with certain no of constants.
Please note that the code provided has few issues. You can follow the modified workaround to execute the fixed code:
function u = fun_u(y)
% Parameters
J1 = 0.1; J2 = 0.1; J3 = 0.1; J4 = 0.1; J5 = 0.1; J6 = 0.1;
S = 0.0001;
GC = 0.1;
Gr = 0.1;
Ha2 = 0.1;
a = 1;
m = 2;
G = 1;
t = 0.1;
phi = 0.1;
% Calculations
exp_t = exp(-t);
u1 = exp_t - 1;
term1 = (-33 / J1) * (1 - exp_t - 2 / 3 * S);
term2 = 2 * GC * J3 + 2 * Gr * J2;
term3 = (2 * J4 * Ha2) / (1 + m^2);
term4 = 3 * GC * exp_t + 6 * exp_t / ((1 - phi)^2.5);
term5 = 2 * GC * J3 * exp_t + 2 * Gr * J2 * exp_t;
u2 = exp_t * (term1 + term2 - term3 - term4 - term5 + term3 * (exp_t - m + m * exp_t)) / (6 * a);
% Function output
u = u1 * y + u2 * y^2;
end
% Define the range of y
y_values = linspace(0, 1, 100);
% Calculate u for each y
u_values = arrayfun(@fun_u, y_values);
% Plot the results
figure;
plot(y_values, u_values);
xlabel('y');
ylabel('u(y)');
title('Plot of u(y)');
axis([0 2 -6 1]); % Adjusted axis limits for visualization after using 'plot'
I have generated a sample array y_values to demonstrate the execution. Please move ahead with using the correct array.
I hope it answers your query.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by