a function with more one variable – in which these variables are derived from other functions
Hey
I am trying to have matlab run accept a function which I have tried to written up as followed.
I want it to calculate "average_density" which is depended on three variables. "porosity_average" and "density_s" which are functions and "z" which is a variable in "average_density" but is also present in the previously mentioned functions. I have gotten a lot different error messages, with must being in the like of either "too many input arguments" or too few – with some instances of it outwright just writing error and the line which the function is in.
I have a feeling this is an amateur error, but I have tried replicating the setup which are shown in other comment sections, though my attempts seemed to fail.
PS. I am not actual trying to make it calculate the average of the density, the newer functioner is already derived from the other density function.
Thank you in advance
porosity = @(z) phi_0 * exp(-z / L);
density_s = @(z) (rho_s_matrix *(1 – porosity(z)) + rho_w * porosity(z));
porosity_average = @(S_initial) (L * phi_0 / S_initial) * (1 – exp(-S_intial / L));
average_density_s = @(porosity_average, density_s,S_intial) density_s(z) * (1 – porosity_average(S_intial)) + rho_w * porosity_average(S);
S = S_initial;
iteration = 0;
max_iterations = 1000; % To prevent infinite loop
while true
iteration = iteration + 1;
average_density_s(density_s) = average_density_s(S, 1000);
W = ((rho_w * S)/average_density_s(z))-S;
S_new = S + W;
fprintf(‘Iteration %d: S = %.2f, W = %.2f, S_new = %.2fn’, iteration, S, W, S_new);
if abs(W) < epsilon
break;
end
S = S_new;
end
S_final = S;
endHey
I am trying to have matlab run accept a function which I have tried to written up as followed.
I want it to calculate "average_density" which is depended on three variables. "porosity_average" and "density_s" which are functions and "z" which is a variable in "average_density" but is also present in the previously mentioned functions. I have gotten a lot different error messages, with must being in the like of either "too many input arguments" or too few – with some instances of it outwright just writing error and the line which the function is in.
I have a feeling this is an amateur error, but I have tried replicating the setup which are shown in other comment sections, though my attempts seemed to fail.
PS. I am not actual trying to make it calculate the average of the density, the newer functioner is already derived from the other density function.
Thank you in advance
porosity = @(z) phi_0 * exp(-z / L);
density_s = @(z) (rho_s_matrix *(1 – porosity(z)) + rho_w * porosity(z));
porosity_average = @(S_initial) (L * phi_0 / S_initial) * (1 – exp(-S_intial / L));
average_density_s = @(porosity_average, density_s,S_intial) density_s(z) * (1 – porosity_average(S_intial)) + rho_w * porosity_average(S);
S = S_initial;
iteration = 0;
max_iterations = 1000; % To prevent infinite loop
while true
iteration = iteration + 1;
average_density_s(density_s) = average_density_s(S, 1000);
W = ((rho_w * S)/average_density_s(z))-S;
S_new = S + W;
fprintf(‘Iteration %d: S = %.2f, W = %.2f, S_new = %.2fn’, iteration, S, W, S_new);
if abs(W) < epsilon
break;
end
S = S_new;
end
S_final = S;
end Hey
I am trying to have matlab run accept a function which I have tried to written up as followed.
I want it to calculate "average_density" which is depended on three variables. "porosity_average" and "density_s" which are functions and "z" which is a variable in "average_density" but is also present in the previously mentioned functions. I have gotten a lot different error messages, with must being in the like of either "too many input arguments" or too few – with some instances of it outwright just writing error and the line which the function is in.
I have a feeling this is an amateur error, but I have tried replicating the setup which are shown in other comment sections, though my attempts seemed to fail.
PS. I am not actual trying to make it calculate the average of the density, the newer functioner is already derived from the other density function.
Thank you in advance
porosity = @(z) phi_0 * exp(-z / L);
density_s = @(z) (rho_s_matrix *(1 – porosity(z)) + rho_w * porosity(z));
porosity_average = @(S_initial) (L * phi_0 / S_initial) * (1 – exp(-S_intial / L));
average_density_s = @(porosity_average, density_s,S_intial) density_s(z) * (1 – porosity_average(S_intial)) + rho_w * porosity_average(S);
S = S_initial;
iteration = 0;
max_iterations = 1000; % To prevent infinite loop
while true
iteration = iteration + 1;
average_density_s(density_s) = average_density_s(S, 1000);
W = ((rho_w * S)/average_density_s(z))-S;
S_new = S + W;
fprintf(‘Iteration %d: S = %.2f, W = %.2f, S_new = %.2fn’, iteration, S, W, S_new);
if abs(W) < epsilon
break;
end
S = S_new;
end
S_final = S;
end too many input arguments or too few. functions MATLAB Answers — New Questions