How i can run this code with simple boundary conditions given in code
이전 댓글 표시
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개)
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.
카테고리
도움말 센터 및 File Exchange에서 Code Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
