So I have this code:(adsbygoogle = window.adsbygoogle || []).push({});

Basically, it's a three-point formula for approximating a derivative, where the variables n = the number of iterations, x = the input value for the sin function, i = iteration number, approx=the approximation of the derivative, and error = the difference between the actual derivative and the approximation.Code (Text):

function ApproxSinDeriv(x,n)

h=.5;

for i = 0:n

h;

approx = (1/(2*h))*(sin(x+h)-sin(x-h));

error = abs(approx-cos(x));

h = h/2;

A=[i,h,approx,error]

end

I put A equal to a matrix of these values, but the output comes out in 30 clunky, individual, one-row matrices.

How would I go about putting this data in an array? That is, one nice clean matrix with 30 rows and 4 columns [i,h,approx,error]?

Thanks!

-Eric.

**Physics Forums | Science Articles, Homework Help, Discussion**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# MATLAB Organizing output in MATLAB

Loading...

Similar Threads for Organizing output MATLAB |
---|

Mathematica Complex output from a real integral |

MATLAB MATLAB: forces acting on an object |

MATLAB Matlab histogram |

Mathematica Storing Mathematica output |

Mathematica DSolve output with unexpected parameters |

**Physics Forums | Science Articles, Homework Help, Discussion**