File: bvpfcn.m Line: 1 Column: 23 Invalid use of operator.
์กฐํ ์: 3 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
Hi, I'm doing a project on chlorine decay in water distribution pipes, to solve this ODE with the following Matlab's BVP4C function . I have wrriten the code but I need to plot the profile C vs x. I have tried searching in MATLAB Answers pertaining to my topics of study, but to no avail. The MATLAB code and the error message are shown below.
At steady state, this can be described by: ๐ท*๐^2๐ถ/๐๐ฅ^2 โ ๐*๐๐ถ/๐๐ฅ โ ๐พ๐ถ = 0 where, ๐ถ is the chlorine concentration (mg/L) at any location ๐ฅ (m) along the pipe, ๐ท is the diffusion coefficient (m2 /s), ๐ is the flow velocity in the pipe (m/s), and ๐พ is the first order decay coefficient (s-1 ). To solve the aforementioned second order ODE, two boundary conditions must be known at the inlet and the outlet of the pipe (i.e., ๐ถ = ๐ถ๐๐ @ ๐ฅ = 0, and ๐ถ = ๐ถ๐๐ข๐ก @ ๐ฅ = ๐ฟ, where L is the pipe length).I have also attached the code/data for your convenience. I appreciate your help with troubleshooting the problem.Thanks for considering my request.
function dydx = bvp4c(@ode,@bc,solinit); % equation to solve
plot(r.x,r.y(1,:),'--o');
title('chlorine decay')
xlabel('pipe length(m)');
ylabel('Concentration (mg/L)');
function dydx = ode(x,y)
D=0.1; % m2/s
U=1; % m/s
K = 1*10^-6; % 1/s
dydx = [y(2);(U*y(2)+k*y(1))/D];
end
function res = bcfcn(ya,yb) %boundary conditions
res = [ya(1)-3 yb(1)-2];
end
function g = guess (x) % initial guess for y and y'
guess = [2;1];
xmesh = linspace(0,1,5);
solinit = bvpinit(xmesh,guess);
๋๊ธ ์: 0
๋ต๋ณ (2๊ฐ)
Steven Lord
2022๋
3์ 18์ผ
When you define a function you need to specify the input arguments as the names of the variables in which the user's input will be stored in the function. You cannot specify them as expressions.
When you call a function you need to pass in an expression. Specifying an unknown variable name as an input argument will not work.
You also don't want to call your function bvp4c since there's already a function by that name in MATLAB.
y = mytimestwo(1:10) % Calling the function I can pass in an expression
y = mytimestwo(z) % Calling the function I cannot pass in an unknown name
% Defining the function I specify a variable name, in this case theInput
%
% When I called this function as y = mytimestwo(1:10) above MATLAB will
% assign 1:10 to the variable theInput inside that mytimestwo call.
function theOutput = mytimestwo(theInput)
theOutput = 2*theInput;
end
% Were I to define a function like below it would error for the same
% reason your function definition would error
%{
function theOutput = mytimestwo(1:10) % Expressions not allowed here
theOutput = 2*theInput;
end
%}
๋๊ธ ์: 0
Torsten
2022๋
3์ 18์ผ
ํธ์ง: Torsten
2022๋
3์ 18์ผ
In principle, this is a direct copy of the first example for bvp4c in the MATLAB documentation.
You only had to give different values to the variables.
function main
xmesh = linspace(0,1,10);
solinit = bvpinit(xmesh, @guess);
sol = bvp4c(@bvpfcn, @bcfcn, solinit);
plot(sol.x, sol.y, '-o')
end
function dydx = bvpfcn(x,y)
D = 0.1; % m2/s
U = 1; % m/s
K = 1*10^-6; % 1/s
dydx = [y(2);(U*y(2)+K*y(1))/D];
end
function res = bcfcn(ya,yb)
res = [ya(1)-3
yb(1)-2];
end
function g = guess(x)
g = [3-x;-1];
end
๋๊ธ ์: 24
Walter Roberson
2022๋
3์ 21์ผ
You have to assign to solinit before you use it.
solinit = bvpinit(xmesh,guess);
r = bvp4c(@ode,@bc,solinit);
์ฐธ๊ณ ํญ๋ชฉ
์นดํ ๊ณ ๋ฆฌ
Help Center ๋ฐ File Exchange์์ Boundary Value Problems์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!