Plotting a graph with given points

12 Ansichten (letzte 30 Tage)
James Pain
James Pain am 13 Nov. 2017
Kommentiert: James Pain am 13 Nov. 2017
I have created a function to compute the Euler of a given IVP as seen below:
function U= Uler(N,h,y)
t = 0;
S = N/h;
for i=1:S
y = y +(h*(0.5*y*(1-y/2)))
t = t +h
end
U=y
end
My question is how do I plot a graph using the values of t and y I obtained during this function?

Antworten (1)

KSSV
KSSV am 13 Nov. 2017
function [t,y]= Uler(N,h,y)
S = N/h;
y = zeros(1,S) ;
t = zeros(1,S) ;
% initial condition
y(1) = 0 ;
t(1) = 0 ;
for i=2:S
y(i) = y(i-1) +(h*(0.5*y*(1-y/2))) ;
t(i) = t(i-1) +h
end
end
[t,y]= Uler(N,h,y) ;
plot(t,y) ;
  1 Kommentar
James Pain
James Pain am 13 Nov. 2017
I've tried putting in this function, and I don't seem to be getting any results, it says Error: "File: Uler.m Line: 13 Column: 1 This statement is not inside any function. (It follows the END that terminates the definition of the function "Uler".)"
and even after putting that plot function before putting end, it still says there's an error on line 9.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Spline Postprocessing finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by