I can't run that code (i'm new)
Afficher commentaires plus anciens
Hello,
I am very new to Matlab and I can't run that code with the following error: Error: The input character is not valid in MATLAB statements or expressions.
Here is the code (I didn't write it):
function err=bdf2(x0=1,h=0.1)
% formule de differences finies BDF2
diff = (3*f(x0)-4*f(x0-h)+f(x0-2*h))/(2*h);
err = abs(diff-df(x0));
fprintf(' x0 %e h %e erreur %e \n',x0,h,err)
% function f
function funct=f(x)
funct = sin(x);
% derivative f
function dfunct=df(x)
dfunct = cos(x);
2 commentaires
We need the full text of the error message, particularly the bit that tells you which line is causing the error.
I've formatted your code as code, but please get rid of the useless blank lines you put in there and next time use the {}Code format button.
Guillaume Fleurisson
le 7 Juil 2017
Réponse acceptée
Plus de réponses (2)
Geoff Hayes
le 7 Juil 2017
Guillaume - since your file has a function named bdf2 then your m-file must be named the same way as bdf2.m. You would then call it from the command line as
bdf2(42,43)
where you would pass in two value for x0 and h. (The 42 and 43 I'm passing in are just for illustration.)
I am surprised by the function signature though
function err=bdf2(x0=1,h=0.1)
I didn't realize that you could provide default values for your input parameters. Are you sure that this is valid?
Guillaume Fleurisson
le 7 Juil 2017
0 votes
Catégories
En savoir plus sur Entering Commands dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!