Home Problems with plotting in Matlab
Reply: 0

Problems with plotting in Matlab

user2021 Published in April 24, 2018, 8:37 am

Hey, I've got a problem plotting a function in Matlab.

I first run this:

format long f = inline('-x.^2');

for i = 0:10 [I(i+1) h(i+1) tid(i+1)] = trapets(f,0,1,2^i); end

trunk = I - log(2);

hold on grid on


t = -7:0; c = polyfit(log(h),log(trunk),1); yy = polyval(c,t); plot(t,yy) grid off hold off

koefficienter = real(c)

and after that I run this file:

hold on


axis([0 0.6 0 0.0014])

Thing is, I don't get any errors, and the plot windows pops up with axes and all, but there is no graph to be found. It's just an empty window with two axes.

Anyone got any ideas?

Edit: Okay, so I'm new to this site and couldn't find the reply button, so I add a reply here instead.

@woodchips : I just realized that I hadn't given you all the information for this problem.. Sorry about that, anyhow I would really appreciate it if someone had the time to help me with this, it would seriously make my week.

This is the part I accidentally left out:

function [ I,h,tid ] = trapets( f,a,b,n )


tic; I=(f(a)+f(b));

for k=2:2:n-2

I = I+2*f(a+k*h);


for k = 1:2:n-1

I = I + 4*f(a+k*h);


I = I * h/3;

tid = toc;


Edit 2: So, I think that the graph I'm seeking is actually getting plotted in the first code that I wrote, the problem is that the variabe 'I' is not changing, which I expect it to do, although the variabels 'n' and 'h' do change. If 'I' was working correctly, I would probably get the right graph (hopefully). Any ideas, anyone?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.340819 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO