error is using bvpset in bvp4c

Hi, I am Syed,
I like to have an output with 6 or more than 6 decimal place (for example: 3.033334), without bvpset i am getting the output upto 4 decimal places, but i like to have upto to 6 or 8 decimal places, please guide me to get the desired output
The error i am getting is
Error using <=
Not enough input arguments.
My program is given below
close all
clc
phi=0.1;
phi1=2;
phi2=2;
Betaf=0.00021;
Betas=0.000058;
sigmaf=0.005;
sigmas=580000;
GR=2;
EM2=20;
Rof=997.1;
Ro=5;
c=0;
Ros=4420;
h=0.5;
Hc=0.25;
K=1;
R=1;
e1=(1./((1-phi).^2.5));
e2=(1-phi)+(phi.*(Ros./Rof));
e3=(1-phi)+phi.*((Ros.*Betas)./(Rof.*Betaf));
sigma=(sigmas./sigmaf);
e4=1-((3*(1-sigma).*phi)./((2+sigma)+(1-sigma).*phi));
gama1=e2./e1;
gama2=1/e1;
gama3=e3./e1;
s1=(e4./(phi1.*(1-i.*Hc)));
s2=(e4./(phi2.*(1-i.*Hc)));
dydx=@(x,y)[y(3);
y(4);
-EM2.*gama2.*y(4)+2.*i.*Ro.*gama1.*y(1)+gama3.*GR.*x+R.*gama1;
(-e4./(1-i.*Hc)).*y(3)];
BC = @(ya,yb)[ya(1);yb(1)-c;ya(4)-s1.*ya(2);yb(4)+s2.*yb(2)];
yinit = [0.01;0.01;0.01;0.01];
options = bvpset('stats','on','RelTol',le-3);
solint = bvpinit(linspace(0,1,50),yinit,options);
U1 = bvp4c(dydx,BC,solint);
dudy1=U1.y(3,1)

 Risposta accettata

Hi @Syed,
I understand that you are aiming to obtain an output with 6 or more decimal places but are encountering errors.
Here are my observations and corrections for your code:
  • The error was because le-3 is not a valid expression. It should be 1e-3, which is the proper MATLAB syntax for .
options = bvpset('stats','on','RelTol',1e-3);
  • The bvpinit function is used to initialize the solution guess and mesh, and it doesn't accept the options structure as an argument.
solint = bvpinit(linspace(0,1,50),yinit);
  • The correct place to pass the options structure is in the bvp4c function call. This allows the solver to use the relative tolerance (RelTol) and print statistics ('stats', 'on').
U1 = bvp4c(dydx,BC,solint,options);
Here is the output following these corrections:
Refer to the following documentations for more details about the functions:
  1. bvpset: https://www.mathworks.com/help/matlab/ref/bvpset.html
  2. bvpinit: https://www.mathworks.com/help/matlab/ref/bvpinit.html
  3. bvp4c: https://www.mathworks.com/help/matlab/ref/bvp4c.html
Hope this solves your query.

4 Commenti

Syed
Syed il 25 Set 2024
Thank you for your answer,
I tried the method you had instructed, but still i am getting 4 decimal places. The output i have shared for your reference.
options = bvpset('stats','on','RelTol',1e-3);
solint = bvpinit(linspace(0,1,50),yinit);
U1 = bvp4c(dydx,BC,solint,options);
The output is
The solution was obtained on a mesh of 50 points.
The maximum residual is 4.394e-05.
There were 499 calls to the ODE function.
There were 14 calls to the BC function.
The solution was obtained on a mesh of 50 points.
The maximum residual is 4.081e-05.
There were 499 calls to the ODE function.
There were 14 calls to the BC function.
The solution was obtained on a mesh of 50 points.
The maximum residual is 6.144e-05.
There were 499 calls to the ODE function.
There were 14 calls to the BC function.
dudy1 =
-0.3003 + 0.1168i
dudy2 =
-0.3062 + 0.1215i
dudy3 =
-0.3058 + 0.1212i
Hi @Syed,
Use this at the start of your program for formatting your output to more decimal digits.
format long
Additionally,
To set the default formatting for long in MATLAB, follow these steps:
- On the MATLAB homepage, go to Home.
- Navigate to Preferences.
- Under Command Window, select Text Display, then choose Numeric Format and set it to long.
Syed
Syed il 25 Set 2024
I got it now, thanks a lot

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2023b

Richiesto:

il 24 Set 2024

Commentato:

il 25 Set 2024

Community Treasure Hunt

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

Start Hunting!

Translated by