Help! MATLAB Code for Rutherford Scattering Won't Run

Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a MATLAB code intended to simulate the trajectory of alpha particles in Rutherford scattering. Participants are seeking assistance in resolving errors that prevent the code from running properly, focusing on both the logic and structure of the code.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant expresses frustration with their inability to run the MATLAB code and requests help in fixing it.
  • Another participant identifies a specific error related to accessing an out-of-bounds index in the array a_x, indicating that it only has one element defined.
  • A different participant suggests that while the code has some redeeming qualities, it contains unnecessary variables that complicate understanding, and emphasizes the need to assign values to all elements of the array a_x before accessing them.
  • Concerns are raised about the clarity of variable names and the overall structure of the code, with suggestions to simplify the code by reducing the number of variables used.
  • Participants discuss the importance of understanding the for loop's operation and recommend simulating iterations manually to diagnose the issue further.

Areas of Agreement / Disagreement

There is no consensus on the overall quality of the code, with some participants finding it problematic while others see potential. The discussion remains unresolved regarding the best approach to fix the identified issues.

Contextual Notes

Limitations include the lack of clarity on the intended logic of the code, the specific requirements for the simulation, and the absence of complete information about variable initialization and usage.

allybally
Messages
2
Reaction score
0
What's wrong with this MATLAB code for Rutherford scattering, it won't run for me! :(

Hi,
I can't do matlab...and have to plot the trajectory of alpha particles in rutherford scattering. I've made an attempt, but i know I've gone wrong somewhere. Could someone tell me how to fix it? I'd be SOOOO thankful...you've no idea!
This is what i have so far, I've added it as an attachment as an m file.

I want it to look something like this:
http://www.kutl.kyushu-u.ac.jp/seminar/MicroWorld1_E/Part2_E/P25_E/Rutherford_S_E.jpg

(and know the way i have it, there should only be one trajectory...i just want it to run! then i'll do it for other impact parameters too.

Thank you so much in advance!
 

Attachments

Last edited by a moderator:
Physics news on Phys.org


I haven't bothered to check the logic of your routine since, well, it's fugly. However, Matlab tells you precisely why your script won't run:

Code:
? Attempted to access a_x(2); index out of bounds because numel(a_x)=1.
 


shoehorn said:
I haven't bothered to check the logic of your routine since, well, it's fugly. However, Matlab tells you precisely why your script won't run:

Code:
? Attempted to access a_x(2); index out of bounds because numel(a_x)=1.

Is it that bad?? would i get any marks for it do you think?? I'm stressing, i don't have a clue whatto do!

Yeah, that's the error that came up,but i don't know how to fix it...do you?
 


The code doesn't look all that bad to me, but it definitely has problems. The variables have names that make it possible to guess what they should contain, and that's a plus, but you might have more variables than you need, which makes understanding the code more difficult.

Your problem is that you have an array a_x with 1 defined element, but in your for loop you are trying to read from a_x(2), a_x(3), etc., but there is no place in your code where you are giving values to these variables.

The first line in your for loop sets velocity_x(2) with the values in v_x(1) and a_x(2) and a_x(1). When do you assign a value to a_x(2)? Do you really need a variable v_x? Why not just use velocity_x instead?

Since you presumably wrote the for loop, you need to understand what it is doing, and you can do that by hand-simulating what the computer will do for an iteration or two at least. Start off with i = 1, and calculate the values that will be stored in velocity_x(2), position_x(2), velocity_y(2), and position_y(2). Doing this should increase your understanding of why you're getting the error you are getting.


A precondition for your for loop is that
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
Replies
5
Views
3K
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K