Clear Filters
Clear Filters

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

3 views (last 30 days)
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

Answers (1)

Shivam
Shivam on 10 Sep 2024
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.

Community Treasure Hunt

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

Start Hunting!