Why isn't MATLAB producing graphs for my program?

  • Thread starter Thread starter iwan89
  • Start date Start date
  • Tags Tags
    Graph Matlab
Click For Summary

Homework Help Overview

The discussion centers around a MATLAB program that is intended to produce graphs but fails to do so. The subject area involves numerical methods and graphical representation of data, particularly in the context of solving differential equations.

Discussion Character

  • Exploratory, Problem interpretation, Assumption checking

Approaches and Questions Raised

  • The original poster attempts to identify the source of the issue preventing graph generation in their MATLAB code. Some participants suggest a potential error in variable naming, specifically between 'U' and 'u'. There is also a follow-up question regarding how to tabulate data from the graph.

Discussion Status

The discussion has seen some guidance offered regarding a possible mistake in the code. However, the original poster has indicated a need for further clarification on a different topic related to data tabulation, suggesting that the conversation is evolving with new questions being introduced.

Contextual Notes

Participants are navigating the specifics of MATLAB syntax and functionality, with some uncertainty about the implications of variable naming conventions in the context of the program's execution.

iwan89
Messages
27
Reaction score
0

Homework Statement


Hello there. I ran a MATLAB program and i can't produce any graph. Please help me


Homework Equations


This are the program


L = 1.;
T = 1.;
maxk = 2500;
dt = T/maxk;
n=50;
dx = L/n;
cond = 1/4;
b = 2.*cond*dt/(dx*dx);
for i= 1:n+1
x(i) = (i-1)*dx;
U(i,1) = sin(pi*x(i));
end
for k=1:maxk+1
u(1,k) = 0.;
u(n+1,k)=0.;
time(k) = (k-1)*dt;
end
for k=1:maxk
for i=2:n;
u(i,k+1)=u(i,k)+0.5*b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
end
end
figure (1)
plot (x,u(:,1),'-',x,u(:,100),'-',x,u(:,300),'-',x,u(:,600),'-')
title ('Temperature within the explicit method')
xlabel ('X')
ylabel ('Y')
figure (2)
mesh (x,time,u')
title ('Temperature within the explicit method')
xlabel ('X')
ylabel ('Temperature')


The Attempt at a Solution


The program works but i can't produce any graph. I think there are little mistake somewhere.. :( pls help me
 
Physics news on Phys.org
I think your problem is this line here

U(i,1) = sin(pi*x(i));

which should have a u(i,1) instead of a U(i,1)
 
  • Like
Likes   Reactions: 1 person
Thank you so much :) really appreciate it :)
1 more thing
how can i tabulate data from the graph?
 
I don't really understand your question (are you asking how to use the tabulate function in matlab?). At any rate you should make a new thread if you have a new question.
 
ok :) i will post a new question
 

Similar threads

  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 22 ·
Replies
22
Views
3K
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K