Why isn't MATLAB producing graphs for my program?

In summary, the conversation is about someone who is having trouble producing a graph in a MATLAB program. They provide the program and mention that there may be a mistake in a particular line. The expert suggests changing a letter in that line. The person thanks the expert and asks for help in tabulating data from the graph. The expert advises them to make a new thread for that question.
  • #1
iwan89
27
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
  • #2
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 1 person
  • #3
Thank you so much :) really appreciate it :)
1 more thing
how can i tabulate data from the graph?
 
  • #4
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.
 
  • #5
ok :) i will post a new question
 

Related to Why isn't MATLAB producing graphs for my program?

1. Why is Matlab not producing a graph?

There could be several reasons for this. Some common causes include incorrect code syntax, missing or incorrect data, or issues with the graphics driver. Double check your code and data, and try updating your graphics driver if the issue persists.

2. How can I fix the "Matlab cannot produce graph" error?

First, check for any error messages in the Command Window. This can help identify the specific issue. You can also try running your code in debug mode, which can help pinpoint errors. Additionally, make sure you have all necessary toolboxes and functions installed for the type of graph you are trying to create.

3. Can a corrupted installation of Matlab cause the "Matlab cannot produce graph" error?

Yes, a corrupted installation can cause various errors in Matlab, including the inability to produce graphs. If you suspect this may be the issue, try reinstalling Matlab and see if the problem persists.

4. My code used to produce a graph in Matlab, but now it doesn't. What could be the reason?

There are a few potential reasons for this. One possibility is that your code has been accidentally changed or deleted. Another reason could be that the data you are trying to graph has changed or is missing. It's also possible that a recent Matlab update has affected the behavior of your code. Check for any changes or updates that may have caused the issue.

5. How can I prevent the "Matlab cannot produce graph" error in the future?

To prevent this error, it's important to write and test your code carefully. Make sure all data is properly formatted and that the necessary functions and toolboxes are installed. It can also be helpful to regularly update your graphics driver and keep an eye out for any changes or updates in Matlab that may affect your code.

Similar threads

  • Calculus and Beyond Homework Help
Replies
2
Views
399
  • Calculus and Beyond Homework Help
Replies
22
Views
1K
  • Calculus and Beyond Homework Help
Replies
1
Views
724
  • Calculus and Beyond Homework Help
Replies
7
Views
2K
  • Calculus and Beyond Homework Help
Replies
10
Views
1K
  • Calculus and Beyond Homework Help
Replies
4
Views
1K
  • Calculus and Beyond Homework Help
Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
9
Views
800
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Calculus and Beyond Homework Help
Replies
6
Views
1K
Back
Top