Getting Error message when using backslash operator
Show older comments
I have tried to set up and use the backslash operator for a system of ODEs and am getting an error message. I think that I am not establishing my y values correctly but I'm not sure how to fix it.

5 Comments
Walter Roberson
on 1 Dec 2020
Edited: Walter Roberson
on 1 Dec 2020
When you run that code, what numeric value are you expecting y(1) to have? I do not mean "describe in general terms what the purpose of y(1) is": I mean what specific numeric value do you expect it to have? 181.932432 ? -5.25623 ? And why that specific numeric value? What is your expectation of how MATLAB is to know that you want to use 654.321 this time or 98765.321 the next time you run the code?
The problem has nothing to do with the \ operator by the way.
Austin Smith
on 2 Dec 2020
Walter Roberson
on 2 Dec 2020
I specifically wrote,
I do not mean "describe in general terms what the purpose of y(1) is"
I mean what specific numeric value do you expect it to have?
I do not what to know what purpose you think y(1) has. You are asking to execute the code, and when you execute that code, y(1) has to have a specific numeric value. The very first time you execute the function, what exact value to you intend y(1) to have, and how do you expect MATLAB to know that is the exact value you want?
Austin Smith
on 2 Dec 2020
Walter Roberson
on 2 Dec 2020
All of the methods you are required to use for solving the ODE are numeric methods. You are not asked to find the formula that gives the answer over the time range: you are being asked to find numeric values at times between 0 and 4.
As such, the program you write cannot operate numerically on the idea that there is a variable y(1): it always needs a specific y(1) value.
Suppose I ask you to plot (x^2-1) over the range 0 to 4. You would probably say, "Okay, easy enough. 0^1-1 is..." -- and then I interrupt you and say, "No, no, I didn't say you could put in specific numeric values! You have to just plot using the idea that there is value to be plotted at, you cannot use any actual values!"
MATLAB needs actual numeric values for your function to process. Process particular set of numeric inputs, record the results, process another particular set of numeric inputs, process the results, and so on, and eventually graph the particular numeric values that you calculated.
It is the difference between having a recipe for making omlette (which tells you the steps you would use if you were to make an omlette) compare to actually cooking an omlette.
Recipe Step 1: get a green vegetable out of the refrigerator and clean it:
Actual cooking Step 1: look in the refrigerator and find all the green vegetables you have there and pick one specific one, and take it out of the refrigerator and clean it.
Running the omlette-cooking program needs the know the specific vegetable, not just the idea that there will be a vegetable.
Accepted Answer
More Answers (0)
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!