The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.
Hmm.. more matlab troubles. I swear I barely understand this program. Anyway.. What i'm trying to do is generate polynomials using A Lagrange Interpolation technique. What I want to know is how do I create actual functions is matlab, that give me an output of say y = 5x^3 + 6x^2 + x + 2?
I know there's a way to do it numerically (just put a value for x in there), but I want the general formula. Can MATLAB do this?
Where in this example, 0 is the first value, 5 is the step size, and 50 is the final value. This will create x as an array of numbers. Remember that in Matlab, the index of the first element is 1. You can also use specific values with brackets: x=[1,2,3,4, 5:6]. etc. Also note that the default step size is 1, so x=0:1:10 is equivalent to x=0:10.
Then you just have to define your function, for example:
y=x.^2
The . indicates each element in the array should be squared. You also must use this with other operators if element by element math is your goal: y=x.*x is equivalent to the above. You will then get an array for y, equal in length to x.
Matlab is incredibly powerful so just an intro. Hope this helps.
I think OP wants a way to represent the function algebraically. No, that is not possible in MATLAB (as far as I know). You want something like Maple if you need to do that.
I think OP wants a way to represent the function algebraically. No, that is not possible in MATLAB (as far as I know). You want something like Maple if you need to do that.
I'll echo that as far as I know as well you can't do this easily... Matlab is really more of a data-analysis program, Maple (i think) or Mathematica are more designed to do mathematics/analysis of actual functions/etc kind of stuff
is there a particular thing you're trying to do? if you just want a graph you can always make the X array very huge, and if you have a decent computer you should be able to get a smooth curve out of it
MATLAB is absolutely capable of doing what you're describing. You can handle simple functions using the symbolic math toolbox (already described), but most of the advanced functions for data analysis will require you to create an actual function (I had to do this the other day using the ode45 command; I couldn't get MATLAB to accept any of my quick-and-dirty symbolic math amalgamations). A function, in MATLAB, is a special type of script file.
I think this might be what you are looking for. It is specifically about solving differential equations numerically, but contains instructions on how to create functions that MATLAB can read.
You are correct sir. However, I was typing that with an orange dripping on my fingers, and typing sparingly with one hand to try NOT to get my keyboard sticky, and to provide a correct answer. I failed at both.
Posts
x=0:5:50
Where in this example, 0 is the first value, 5 is the step size, and 50 is the final value. This will create x as an array of numbers. Remember that in Matlab, the index of the first element is 1. You can also use specific values with brackets: x=[1,2,3,4, 5:6]. etc. Also note that the default step size is 1, so x=0:1:10 is equivalent to x=0:10.
Then you just have to define your function, for example:
y=x.^2
The . indicates each element in the array should be squared. You also must use this with other operators if element by element math is your goal: y=x.*x is equivalent to the above. You will then get an array for y, equal in length to x.
Matlab is incredibly powerful so just an intro. Hope this helps.
I'll echo that as far as I know as well you can't do this easily... Matlab is really more of a data-analysis program, Maple (i think) or Mathematica are more designed to do mathematics/analysis of actual functions/etc kind of stuff
is there a particular thing you're trying to do? if you just want a graph you can always make the X array very huge, and if you have a decent computer you should be able to get a smooth curve out of it
Here's an example of its use:
f = x^2;
syms x;
diff(f)
int(f)
should see 2x and x^3. that syms command tells matlab what you've called your variable, so it doesn't try to treat it as a constant.
I think this might be what you are looking for. It is specifically about solving differential equations numerically, but contains instructions on how to create functions that MATLAB can read.
And horizon, you would see 2x and x^3/3 :P
Case closed.