Does somebody know what is wrong with my parantheses in this code?

I have difficulties calling the function i named newton. Since the variable dlam(i) is in a loop it should be dependant on i as well but matlab is displaying a parantheses error.
Thanks in advance

2 commentaires

Scott MacKenzie
Scott MacKenzie le 12 Juil 2021
Modifié(e) : Scott MacKenzie le 12 Juil 2021
One thing at a time. Concerning your first bug, looks like you need to hone your skills on defining anonymous functions. I suggest you start by studying Anonymous Functions in the MATLAB documentatioin.
You are probably right, thanks

Connectez-vous pour commenter.

 Réponse acceptée

When you are defining an anonymous function, the part directly after the @ must be a list of plain variable names, with no indexing permitted.
It is true that your functions depend upon i, but you are redefining the function inside the for i loop, so you can just let i be a constant relative to the anonymous function -- like
f = @(dlam) (sqrt(3/2) etc)
Are you certain, though, that the calculation for dlam(i) should be in terms of dlam(i+1) even though you are looping forward? It would make more sense to me if dlam(i+1) was in terms of dlam(i) or if you were looping backwards so you calculated dlam(i+1) before you calculated dlam(i)

1 commentaire

Actually it was
f = @dlam(i+1) (sqrt(3/2) etc)
before but i tried out a lot of things and forgot to put the +1 back in.
I used the iteration i+1 because of the rest of the code at the bottom. But i will try to use it as an integer without index.
Thank you for the fast answer.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Produits

Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by